-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
index.test-d.ts
52 lines (38 loc) · 1.08 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
import {expectError} from '../../../..';
import {default as one, atLeastOne, foo, getFoo, HasKey, hasProperty, MyClass, Options, triggerSuggestion, ReadonlyKeys} from '.';
expectError<string>(1);
expectError<string>('fo');
expectError(foo.bar = 'quux');
expectError(foo.quux);
// Ignore errors in deeply nested blocks too
try {
if (true) {
expectError(foo.bar = 'quux');
expectError(foo.quux);
}
} catch (error) {
expectError(error.code);
}
expectError(hasProperty({name: 1}));
expectError(one(1));
expectError(one(1, 2, 3));
expectError({} as Options);
expectError(atLeastOne())
expectError(getFoo({bar: 1} as HasKey<'bar'>));
const bar = 1;
expectError(bar());
expectError(new bar());
expectError(MyClass());
// 'new' expression, whose target lacks a construct signature, implicitly has an 'any' type.
expectError(new hasProperty({name: 'foo'}));
expectError(() => {
triggerSuggestion.fooOrBar = 'fooo';
})
expectError(triggerSuggestion.fooOrBars);
expectError(() => {
const foo: ReadonlyKeys = {
bar: 'baz',
};
// ts2542 - trying to modify readonly key
foo.bar = 'bar';
});