Skip to content
This repository has been archived by the owner on Nov 9, 2024. It is now read-only.

Commit

Permalink
Handle types for null in duration/delay arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiks committed Oct 21, 2019
1 parent 5013e28 commit 9a0d640
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
12 changes: 10 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ import bindGlobalEventListeners, {
} from './bindGlobalEventListeners';
import {getArrayOfElements, isReferenceElement, isElement} from './utils';
import {warnWhen, validateTargets, validateProps} from './validation';
import {Props, Instance, Targets, HideAllOptions, Plugin, Tippy} from './types';
import {
Props,
Instance,
Targets,
HideAllOptions,
Plugin,
Tippy,
DefaultProps,
} from './types';

/**
* Exported module
Expand Down Expand Up @@ -68,7 +76,7 @@ tippy.currentInput = currentInput;
/**
* Mutates the defaultProps object by setting the props specified
*/
function setDefaultProps(partialProps: Partial<Props>): void {
function setDefaultProps(partialProps: Partial<DefaultProps>): void {
if (__DEV__) {
validateProps(partialProps, []);
}
Expand Down
4 changes: 2 additions & 2 deletions src/props.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Props, Plugin} from './types';
import {Props, DefaultProps, Plugin} from './types';

export const defaultProps: Props = {
export const defaultProps: DefaultProps = {
allowHTML: true,
animation: 'fade',
appendTo: (): Element => document.body,
Expand Down
9 changes: 7 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ export interface Props extends LifecycleHooks {
arrow: boolean | string | SVGElement;
boundary: 'scrollParent' | 'window' | 'viewport' | HTMLElement;
content: Content;
delay: number | [number, number];
delay: number | [number | null, number | null];
distance: number | string;
duration: number | [number, number];
duration: number | [number | null, number | null];
flip: boolean;
flipBehavior: 'flip' | Placement[];
flipOnUpdate: boolean;
Expand All @@ -76,6 +76,11 @@ export interface Props extends LifecycleHooks {
[key: string]: any;
}

export interface DefaultProps extends Props {
delay: number | [number, number];
duration: number | [number, number];
}

export interface AnimateFillProps {
animateFill: boolean;
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export function getArrayOfElements(value: Targets): Element[] {
* Returns a value at a given index depending on if it's an array or number
*/
export function getValueAtIndexOrReturn<T>(
value: T | T[],
value: T | [T | null, T | null],
index: number,
defaultValue: T | T[],
defaultValue: T | [T, T],
): T {
if (Array.isArray(value)) {
const v = value[index];
Expand Down

0 comments on commit 9a0d640

Please sign in to comment.