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

Commit 7eb1c8e

Browse files
authored
Use KnownProps to ignore index signature (#137)
* Fix: Use KnownProps to ignore index signature * Add index signature to extended types Allows backwards-compatibility for typeless plugin props * Use KnownSingletonProps for useSingleton() types
1 parent 4a3ca12 commit 7eb1c8e

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

index.d.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,48 @@
11
import * as React from 'react';
22
import {default as tippyCore, Instance, Props, Plugin} from 'tippy.js';
33

4-
export interface TippyProps extends Omit<Partial<Props>, 'content'> {
4+
type KnownKeys<T> = {
5+
[K in keyof T]: string extends K ? never : number extends K ? never : K;
6+
} extends {[_ in keyof T]: infer U}
7+
? U
8+
: never;
9+
10+
export type KnownProps = Pick<Props, KnownKeys<Props>>;
11+
12+
export interface TippyProps extends Omit<Partial<KnownProps>, 'content'> {
513
content: React.ReactChild | React.ReactChild[];
614
children: React.ReactElement<any>;
715
visible?: boolean;
816
enabled?: boolean;
917
className?: string;
1018
plugins?: Plugin[];
1119
singleton?: (instance: Instance) => void;
20+
[key: string]: any;
1221
}
1322

1423
declare const Tippy: React.ForwardRefExoticComponent<TippyProps>;
1524
export default Tippy;
1625

1726
export const tippy: typeof tippyCore;
1827

19-
export interface TippySingletonProps extends Partial<Props> {
28+
export interface TippySingletonProps extends Partial<KnownProps> {
2029
children: Array<React.ReactElement<any>>;
2130
className?: string;
2231
plugins?: Plugin[];
32+
[key: string]: any;
2333
}
2434

2535
export const TippySingleton: React.FunctionComponent<TippySingletonProps>;
2636

27-
export type UseSingletonProps = Omit<TippySingletonProps, 'children'>;
37+
type KnownSingletonProps = Pick<
38+
TippySingletonProps,
39+
KnownKeys<TippySingletonProps>
40+
>;
41+
42+
export interface UseSingletonProps
43+
extends Omit<KnownSingletonProps, 'children'> {
44+
[key: string]: any;
45+
}
2846

2947
export const useSingleton: (
3048
props?: UseSingletonProps,

0 commit comments

Comments
 (0)