forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtst.ts
More file actions
119 lines (91 loc) · 2.23 KB
/
tst.ts
File metadata and controls
119 lines (91 loc) · 2.23 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
var foo: MyInterface = 123 as any;
interface MyInterface {
function (): number; // OK - Highly unlikely that it is an accident when there are other named methods in the interface.
(): number; // OK - What was probably meant above.
new:() => void; // OK - This is a property, not a method, we ignore those.
constructor(): string; // $ Alert - This a called "constructor"
new(): Date; // OK - This a constructor signature.
myNumber: 123;
}
var a : MyFunction = null as any;
interface MyFunction {
function(): number; // $ Alert
}
class Foo {
new(): number { // OK - Highly unlikely that a developer confuses "constructor" and "new" when both are present.
return 123;
}
constructor() { // OK - This is a constructor.
}
myString = "foobar"
myMethod(): boolean {
return Math.random() > 0.5;
}
}
var b : FunctionClass = new FunctionClass();
declare class FunctionClass {
function(): number; // $ Alert
}
class Baz {
new(): Baz { // OK - When there is a method body I assume the developer knows what they are doing.
return null as any;
}
}
declare class Quz {
new(): Quz; // $ Alert - The developer likely meant to write constructor.
}
var bla = new Foo();
var blab = new Baz();
interface X {
constructor: () => string; // Just a property, not a method.
}
type A = {
function(): number; // $ Alert
};
type B = {
constructor(): number; // $ Alert
new(): number;
};
class StaticMethods {
static function(): void {}
static new(): void {}
}
interface Overloaded {
function(x: string): string; // $Alert
function(x: number): number; // $Alert
function(x: any): any; // $Alert
}
abstract class AbstractFoo {
abstract new(): void; // $Alert
}
abstract class AbstractFooFunction {
abstract function(): number; // $Alert
}
abstract class AbstractFooConstructor {
constructor(){}
}
declare module "some-module" {
interface ModuleInterface {
function(): void; // $Alert
}
}
type Intersection = {
function(): number; // $Alert
} & {
other(): string;
};
type Union = {
new(): number;
} | {
valid(): string;
};
type Union2 = {
constructor(): number; // $Alert
} | {
valid(): string;
};
type Intersection2 = {
constructor(): number; // $Alert
} & {
other(): string;
};