diff --git a/index.test-d.ts b/index.test-d.ts index 016cf0c19..61848a2da 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -17,6 +17,17 @@ import tippy, { CreateSingletonInstance, } from './src/types'; +interface CustomProps { + custom: number; +} + +type FilteredProps = CustomProps & + Omit; + +type ExtendedProps = FilteredProps & LifecycleHooks; + +declare const tippyExtended: Tippy; + const singleTarget = document.createElement('div'); const mulitpleTargets = document.querySelectorAll('div'); @@ -37,6 +48,8 @@ expectType( ); const tippyInstances = [tippy(singleTarget), tippy(singleTarget)]; +const singleton = createSingleton(tippyInstances); + expectType(createSingleton(tippyInstances)); expectType( createSingleton(tippyInstances, {content: 'hello'}) @@ -44,6 +57,12 @@ expectType( expectType( createSingleton(tippyInstances, {overrides: ['content']}) ); +expectType<(instances: Instance[]) => 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( tippy(singleTarget, { @@ -51,17 +70,6 @@ expectType( }) ); -interface CustomProps { - custom: number; -} - -type FilteredProps = CustomProps & - Omit; - -type ExtendedProps = FilteredProps & LifecycleHooks; - -declare const tippyExtended: Tippy; - const customPlugin: Plugin = { name: 'custom', defaultValue: 42, diff --git a/src/types.ts b/src/types.ts index 2e8845885..ab8c9e870 100644 --- a/src/types.ts +++ b/src/types.ts @@ -185,11 +185,11 @@ export type CreateSingletonProps = TProps & { export type CreateSingletonInstance = Instance< TProps > & { - setInstances(instances: Instance[]): void; + setInstances(instances: Instance[]): void; }; export type CreateSingleton = ( - tippyInstances: Instance[], + tippyInstances: Instance[], optionalProps?: Partial> ) => CreateSingletonInstance>;