forked from sindresorhus/electron-store
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.test-d.ts
63 lines (50 loc) · 1.34 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
import {expectType, expectAssignable} from 'tsd';
import Store, {Schema} from './index.js';
new Store({defaults: {}}); // eslint-disable-line no-new
new Store({name: 'myConfiguration'}); // eslint-disable-line no-new
const store = new Store();
store.set('foo', 'bar');
store.set({
foo: 'bar',
foo2: 'bar2',
});
store.delete('foo');
store.get('foo');
store.get('foo', 42);
store.reset('foo');
store.has('foo');
store.clear();
await store.openInEditor();
store.size; // eslint-disable-line @typescript-eslint/no-unused-expressions
store.store; // eslint-disable-line @typescript-eslint/no-unused-expressions
store.store = {
foo: 'bar',
};
store.path; // eslint-disable-line @typescript-eslint/no-unused-expressions
type TypedStore = {
isEnabled: boolean;
interval: number;
};
const typedStore = new Store<TypedStore>({
defaults: {
isEnabled: true,
interval: 30_000,
},
});
expectType<number>(typedStore.get('interval'));
const isEnabled = false;
typedStore.set('isEnabled', isEnabled);
typedStore.set({
isEnabled: true,
interval: 10_000,
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const offDidChange = typedStore.onDidChange(
'isEnabled',
(newValue, oldValue) => {
expectType<boolean | undefined>(newValue);
expectType<boolean | undefined>(oldValue);
},
);
expectAssignable<() => void>(offDidChange);
offDidChange();