forked from sindresorhus/conf
/
index.test-d.ts
57 lines (50 loc) · 1.64 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
import {expectType, expectError} from 'tsd';
import Conf = require('.');
const conf = new Conf<string | number | boolean>();
new Conf<string>({
defaults: {
foo: 'bar',
unicorn: 'rainbow'
}
});
new Conf<string>({configName: ''});
new Conf<string>({projectName: 'foo'});
new Conf<string>({cwd: ''});
new Conf<string>({encryptionKey: ''});
new Conf<string>({encryptionKey: new Buffer('')});
new Conf<string>({encryptionKey: new Uint8Array([1])});
new Conf<string>({encryptionKey: new DataView(new ArrayBuffer(2))});
new Conf<string>({fileExtension: '.foo'});
new Conf<string>({clearInvalidConfig: false});
new Conf<string>({serialize: value => 'foo'});
new Conf<string>({deserialize: string => ({})});
new Conf<string>({projectSuffix: 'foo'});
new Conf<string>({schema: {foo: {type: 'string'}}});
expectError(new Conf<string>({schema: {foo: {type: 'nope'}}}));
conf.set('foo', 'bar');
conf.set('hello', 1);
conf.set('unicorn', false);
expectType<string | number | boolean>(conf.get('foo'));
expectType<string | number | boolean>(conf.get('foo', 'bar'));
conf.delete('foo');
expectType<boolean>(conf.has('foo'));
conf.clear();
const off = conf.onDidChange('foo', (oldValue, newValue) => {
expectType<string | number | boolean | undefined>(oldValue);
expectType<string | number | boolean | undefined>(newValue);
});
expectType<() => void>(off);
off();
conf.store = {
foo: 'bar',
unicorn: 'rainbow'
};
expectType<string>(conf.path);
expectType<number>(conf.size);
expectType<IterableIterator<[string, string | number | boolean]>>(
conf[Symbol.iterator]()
);
for (const [key, value] of conf) {
expectType<string>(key);
expectType<string | number | boolean>(value);
}