This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
/
test.ts.lint
85 lines (61 loc) · 1.81 KB
/
test.ts.lint
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
[typescript]: >= 2.4.0 < 3.5.0
// Catches explicit union types.
type SomeType =
| null
~~~~
| undefined
~~~~~~~~~~~~~~~
| boolean;
~~~~~~~~~~~~~ [0]
const c: string | null | undefined;
~~~~~~~~~~~~~~~~~~~~~~~~~ [0]
const someFunc = (): string | undefined | null => {}
~~~~~~~~~~~~~~~~~~~~~~~~~ [0]
const someFunc = (foo: null | string | undefined, bar: boolean) => {}
~~~~~~~~~~~~~~~~~~~~~~~~~ [0]
interface SomeInterface {
foo: number | null | undefined;
~~~~~~~~~~~~~~~~~~~~~~~~~ [0]
bar: boolean;
}
function someFunc(): Promise<number | undefined | null> {} // error
~~~~~~~~~~~~~~~~~~~~~~~~~ [0]
function someFunc(bar: boolean, foo: undefined | number | null) {}
~~~~~~~~~~~~~~~~~~~~~~~~~ [0]
// Catches implicit return types.
function testFunc() {
~~~~~~~~~~~~~~~~~~~~~
const somePredicate = (): boolean => true;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const someFunc = (): string | null => null;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
let foo;
~~~~~~~~~~~~
if (somePredicate()) {
~~~~~~~~~~~~~~~~~~~~~~~~~~
foo = someFunc();
~~~~~~~~~~~~~~~~~~~~~~~~~
}
~~~~~
return foo;
~~~~~~~~~~~~~~~
}
~ [0]
// Does not consider ? as shorthand for undefined.
type Text = string | null
interface TextInterface {
foo?: Text
}
interface SuperTextInterface {
bar?: Text | number
}
function someFunc(foo?: Text, bar?: Text | number) {}
// Ignores implicit union types.
const x: SomeType;
const someFunc = (): SomeType => {}
function(foo: SomeInterface) {}
const y = testFunc();
// Unless they are explicitly unioned.
const z: Text | undefined;
~~~~~~~~~~~~~~~~ [0]
[0]: Union type cannot include both 'null' and 'undefined'.