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
|
interface ifc { }
// Attempting to 'new' an interface yields poor error
var i = new ifc();
// Parens are optional
var x = new Date;
var y = new Date();
// Target is not a class or var, good error
var t1 = new 53();
var t2 = new ''();
new string;
// Use in LHS of expression?
(new Date()).toString();
// Various spacing
var t3 = new string[]( );
var t4 =
new
string
[
]
(
);
// Unresolved symbol
var f = new q();
// not legal
var t5 = new new Date;
// Can be an expression
new String;
// Error on union
declare const union: { a: string } | { b: string }
new union;
// Error on union with one constructor
declare const ctorUnion: { a: string } | (new (a: string) => void)
new ctorUnion("");
// Error on union with incompatible constructors
declare const ctorUnion2: (new <T extends number>(a: T) => void) | (new <T>(a: string) => void)
new ctorUnion2("");
module M {
export class T {
x: number;
}
}
class S {
public get xs(): M.T[] {
return new M.T[];
}
}
|