Skip to content

Commit

Permalink
fix(types): use any for Instance generic
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiks committed Apr 17, 2020
1 parent 128a32e commit d01a815
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
30 changes: 19 additions & 11 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ import tippy, {
CreateSingletonInstance,
} from './src/types';

interface CustomProps {
custom: number;
}

type FilteredProps = CustomProps &
Omit<Props, keyof CustomProps | keyof LifecycleHooks>;

type ExtendedProps = FilteredProps & LifecycleHooks<FilteredProps>;

declare const tippyExtended: Tippy<ExtendedProps>;

const singleTarget = document.createElement('div');
const mulitpleTargets = document.querySelectorAll('div');

Expand All @@ -37,31 +48,28 @@ expectType<DelegateInstance[]>(
);

const tippyInstances = [tippy(singleTarget), tippy(singleTarget)];
const singleton = createSingleton(tippyInstances);

expectType<CreateSingletonInstance>(createSingleton(tippyInstances));
expectType<CreateSingletonInstance>(
createSingleton(tippyInstances, {content: 'hello'})
);
expectType<CreateSingletonInstance>(
createSingleton(tippyInstances, {overrides: ['content']})
);
expectType<(instances: Instance<any>[]) => void>(singleton.setInstances);

// TODO: I want to assert that these *don't* error, but `tsd` does not provide
// such a function(?)
createSingleton(tippyExtended('button'));
singleton.setInstances(tippyExtended('button'));

expectType<Instance>(
tippy(singleTarget, {
plugins: [animateFill, followCursor, inlinePositioning, sticky],
})
);

interface CustomProps {
custom: number;
}

type FilteredProps = CustomProps &
Omit<Props, keyof CustomProps | keyof LifecycleHooks>;

type ExtendedProps = FilteredProps & LifecycleHooks<FilteredProps>;

declare const tippyExtended: Tippy<ExtendedProps>;

const customPlugin: Plugin<ExtendedProps> = {
name: 'custom',
defaultValue: 42,
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ export type CreateSingletonProps<TProps = Props> = TProps & {
export type CreateSingletonInstance<TProps = CreateSingletonProps> = Instance<
TProps
> & {
setInstances(instances: Instance<TProps>[]): void;
setInstances(instances: Instance<any>[]): void;
};

export type CreateSingleton<TProps = Props> = (
tippyInstances: Instance<TProps | Props>[],
tippyInstances: Instance<any>[],
optionalProps?: Partial<CreateSingletonProps<TProps>>
) => CreateSingletonInstance<CreateSingletonProps<TProps>>;

Expand Down

0 comments on commit d01a815

Please sign in to comment.