This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
/
test.ts.lint
70 lines (52 loc) · 2.75 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
declare class Promise<T>{}
const nonAsyncPromiseFunctionExpressionA = function(p: Promise<void>) { return p; };
~~~~~~~~~~~~~~~~~~~~~~~~~~ [0]
const nonAsyncPromiseFunctionExpressionB = function() { return new Promise<void>(); };
~~~~~~~~~~ [0]
// 'async' 'Promise'-returning function expressions are allowed
const asyncPromiseFunctionExpressionA = async function(p: Promise<void>) { return p; };
const asyncPromiseFunctionExpressionB = async function() { return new Promise<void>(); };
// non-'async' non-'Promise'-returning function expressions are allowed
const nonAsyncNonPromiseFunctionExpression = function(n: number) { return n; };
function nonAsyncPromiseFunctionDeclarationA(p: Promise<void>) { return p; }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0]
function nonAsyncPromiseFunctionDeclarationB() { return new Promise<void>(); }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0]
// 'async' 'Promise'-returning function declarations are allowed
async function asyncPromiseFunctionDeclarationA(p: Promise<void>) { return p; }
async function asyncPromiseFunctionDeclarationB() { return new Promise<void>(); }
// non-'async' non-'Promise'-returning function declarations are allowed
function nonAsyncNonPromiseFunctionDeclaration(n: number) { return n; }
const nonAsyncPromiseArrowFunctionA = (p: Promise<void>) => p;
~~~~~~~~~~~~~~~~~~~~~ [0]
const nonAsyncPromiseArrowFunctionB = () => new Promise<void>();
~~~~~ [0]
// 'async' 'Promise'-returning arrow functions are allowed
const asyncPromiseArrowFunctionA = async (p: Promise<void>) => p;
const asyncPromiseArrowFunctionB = async () => new Promise<void>();
// non-'async' non-'Promise'-returning arrow functions are allowed
const nonAsyncNonPromiseArrowFunction = (n: number) => n;
class Test {
public nonAsyncPromiseMethodA(p: Promise<void>) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0]
return p;
}
public nonAsyncPromiseMethodB() {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0]
return new Promise<void>();
}
// 'async' 'Promise'-returning methods are allowed
public async asyncPromiseMethodA(p: Promise<void>) {
return p;
}
public async asyncPromiseMethodB() {
return new Promise<void>();
}
// non-'async' non-'Promise'-returning methods are allowed
public nonAsyncNonPromiseMethod(n: number) {
return n;
}
// single statement lamda functions that delegate to another promise-returning function are allowed
public delegatingMethod = () => this.asyncPromiseMethodB(1);
}
[0]: functions that return promises must be async