This repository has been archived by the owner on Nov 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 523
/
index.test-d.ts
93 lines (75 loc) · 2.41 KB
/
index.test-d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import {expectType} from 'tsd';
import tippy, {
Instance,
Props,
Tippy,
LifecycleHooks,
delegate,
DelegateInstance,
createSingleton,
Plugin,
animateFill,
followCursor,
inlinePositioning,
sticky,
hideAll,
roundArrow,
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');
expectType<Instance>(tippy(singleTarget));
expectType<Instance>(tippy(singleTarget, {content: 'hello'}));
expectType<Instance[]>(tippy(mulitpleTargets));
expectType<Instance[]>(tippy(mulitpleTargets, {content: 'hello'}));
expectType<DelegateInstance>(delegate(singleTarget, {target: '.child'}));
expectType<DelegateInstance>(
delegate(singleTarget, {target: '.child', content: 'hello'})
);
expectType<DelegateInstance[]>(delegate(mulitpleTargets, {target: '.child'}));
expectType<DelegateInstance[]>(
delegate(mulitpleTargets, {target: '.child', content: 'hello'})
);
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],
})
);
const customPlugin: Plugin<ExtendedProps> = {
name: 'custom',
defaultValue: 42,
fn(instance) {
expectType<Instance<ExtendedProps>>(instance);
expectType<number>(instance.props.custom);
return {};
},
};
expectType<Instance<ExtendedProps>>(
tippyExtended(singleTarget, {
custom: 42,
plugins: [customPlugin],
})
);
expectType<void>(hideAll({duration: 50, exclude: tippy(singleTarget)}));
expectType<string>(roundArrow);