This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
/
test.ts.lint
92 lines (80 loc) · 1.97 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
86
87
88
89
90
91
92
class Promise<T> {
then(): Promise<T>;
}
function valueWrong(): number | undefined {
return;
~~~~~~~ [UNDEFINED]
}
function valueRight(): number | undefined {
return undefined;
}
function voidWrong(): void {
return undefined;
~~~~~~~~~~~~~~~~~ [VOID]
}
function voidRight(): void {
return;
}
// Infers type from context.
[].forEach(() => {
return undefined;
~~~~~~~~~~~~~~~~~ [VOID]
});
[].map<number | undefined>(() => {
return;
~~~~~~~ [UNDEFINED]
});
type Cb = () => void;
declare function badContextualType(cb: Cb | Cb[]): void;
// Uses typeAtLocation instead of contextual type.
badContextualType(() => {
if (1 === 2) return 1;
else return;
~~~~~~~ [UNDEFINED]
});
// Allow anything in callback taking 'any'.
function takesAnyCb(cb: () => any): void;
takesAnyCb(() => { return; });
takesAnyCb(() => { return undefined; });
takesAnyCb(() => {
if (1 === 2) return;
else return 1;
});
takesAnyCb(() => {
if (1 === 2) return;
else return undefined;
});
takesAnyCb((): void => {
if (1 === 2) return;
else return undefined;
~~~~~~~~~~~~~~~~~ [VOID]
});
async function promiseVoid(): Promise<void> {
if (1 === 2) return;
else return undefined;
~~~~~~~~~~~~~~~~~ [VOID]
}
async function promiseValue(): Promise<number | undefined> {
if (1 === 2) return 1;
else return;
~~~~~~~ [UNDEFINED]
}
declare function test(cb: () => Promise<void> | void): void;
test(async () => {
if (1 === 2) return;
else return undefined;
~~~~~~~~~~~~~~~~~ [VOID]
});
function * generator(returnNothing: boolean) {
if (returnNothing) return;
yield 1;
return yield * [2, 3];
}
class ClassWithGeneratorMethod {
* generatorMethod(returnNothing: boolean) {
if (returnNothing) return;
yield 1;
}
}
[VOID]: `void` function should use `return;`, not `return undefined;`.
[UNDEFINED]: Value-returning function should use `return undefined;`, not just `return;`.