forked from microsoft/tslint-microsoft-contrib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.ts.lint
66 lines (51 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
let a: string[];
let b: Array<string> = [];
~~~~~~~~~~~~~ [type % ("Array<string>")]
interface C {
myArray: Array<string>;
~~~~~~~~~~~~~ [type % ("Array<string>")]
}
var d: Array<string>;
~~~~~~~~~~~~~ [type % ("Array<string>")]
function e(param: Array<number>) { }
~~~~~~~~~~~~~ [type % ("Array<number>")]
var f = new Array();
~~~~~~~~~~~ [constructor % ("new Array()")]
var g = new Array(4, 5);
~~~~~~~~~~~~~~~ [constructor % ("new Array(4, 5)")]
var h = new Array(4);
var i = Array(2);
var j = new Array;
~~~~~~~~~ [constructor % ("new Array")]
// calls to Array function/constructor on global objects is forbidden
var nc1 = window.Array(1);
var nc2 = global.Array(1, 2);
~~~~~~~~~~~~~~~~~~ [function % ("global.Array(1, 2)")]
var nc3 = globalThis.Array('3'); // no error - limitation of untyped rule
var nn1 = new window.Array(1);
var nn2 = new global.Array(1, 2);
~~~~~~~~~~~~~~~~~~~~~~ [constructor % ("new global.Array(1, 2)")]
var nn3 = new globalThis.Array('3'); // no error - limitation of untyped rule
// calls to Array function/constructor from namespaces are valid
import { Types } from 'mongoose';
export const foo: Types.Array<number> = new Types.Array();
declare var num: number;
declare var str: string;
declare var unionA: number | Array<number>;
~~~~~~~~~~~~~ [type % ("Array<number>")]
declare var unionF: number | (() => number);
// no errors below - limitation of untyped rule
const t1 = Array(num);
const t2 = Array(str);
const t3 = Array(unionA);
const t3 = Array(unionF);
const t4 = Array(num + 1);
const t5 = Array(str + 1);
const t6 = Array(10 + 1);
const t7 = Array(10 + '1');
const t8 = Array(1.5);
const t9 = Array(-1);
const t10 = Array(-num);
[type]: Replace generic-typed Array with array literal: %s
[constructor]: Replace Array constructor with an array literal: %s
[function]: Replace Array function with an array literal: %s