mirror of
https://github.com/github/codeql.git
synced 2025-12-18 18:10:39 +01:00
53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
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();
|