diff --git a/tests/baselines/reference/classExtendingBuiltinType.js b/tests/baselines/reference/classExtendingBuiltinType.js new file mode 100644 index 00000000000..666ada39505 --- /dev/null +++ b/tests/baselines/reference/classExtendingBuiltinType.js @@ -0,0 +1,90 @@ +//// [classExtendingBuiltinType.ts] +class C1 extends Object { } +class C2 extends Function { } +class C3 extends String { } +class C4 extends Boolean { } +class C5 extends Number { } +class C6 extends Date { } +class C7 extends RegExp { } +class C8 extends Error { } +class C9 extends Array { } +class C10 extends Array { } + + +//// [classExtendingBuiltinType.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var C1 = (function (_super) { + __extends(C1, _super); + function C1() { + _super.apply(this, arguments); + } + return C1; +})(Object); +var C2 = (function (_super) { + __extends(C2, _super); + function C2() { + _super.apply(this, arguments); + } + return C2; +})(Function); +var C3 = (function (_super) { + __extends(C3, _super); + function C3() { + _super.apply(this, arguments); + } + return C3; +})(String); +var C4 = (function (_super) { + __extends(C4, _super); + function C4() { + _super.apply(this, arguments); + } + return C4; +})(Boolean); +var C5 = (function (_super) { + __extends(C5, _super); + function C5() { + _super.apply(this, arguments); + } + return C5; +})(Number); +var C6 = (function (_super) { + __extends(C6, _super); + function C6() { + _super.apply(this, arguments); + } + return C6; +})(Date); +var C7 = (function (_super) { + __extends(C7, _super); + function C7() { + _super.apply(this, arguments); + } + return C7; +})(RegExp); +var C8 = (function (_super) { + __extends(C8, _super); + function C8() { + _super.apply(this, arguments); + } + return C8; +})(Error); +var C9 = (function (_super) { + __extends(C9, _super); + function C9() { + _super.apply(this, arguments); + } + return C9; +})(Array); +var C10 = (function (_super) { + __extends(C10, _super); + function C10() { + _super.apply(this, arguments); + } + return C10; +})(Array); diff --git a/tests/baselines/reference/classExtendingBuiltinType.symbols b/tests/baselines/reference/classExtendingBuiltinType.symbols new file mode 100644 index 00000000000..08e85be570e --- /dev/null +++ b/tests/baselines/reference/classExtendingBuiltinType.symbols @@ -0,0 +1,41 @@ +=== tests/cases/conformance/classes/classDeclarations/classExtendingBuiltinType.ts === +class C1 extends Object { } +>C1 : Symbol(C1, Decl(classExtendingBuiltinType.ts, 0, 0)) +>Object : Symbol(Object, Decl(lib.d.ts, 92, 1), Decl(lib.d.ts, 223, 11)) + +class C2 extends Function { } +>C2 : Symbol(C2, Decl(classExtendingBuiltinType.ts, 0, 27)) +>Function : Symbol(Function, Decl(lib.d.ts, 223, 38), Decl(lib.d.ts, 269, 11)) + +class C3 extends String { } +>C3 : Symbol(C3, Decl(classExtendingBuiltinType.ts, 1, 29)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11)) + +class C4 extends Boolean { } +>C4 : Symbol(C4, Decl(classExtendingBuiltinType.ts, 2, 27)) +>Boolean : Symbol(Boolean, Decl(lib.d.ts, 443, 38), Decl(lib.d.ts, 456, 11)) + +class C5 extends Number { } +>C5 : Symbol(C5, Decl(classExtendingBuiltinType.ts, 3, 28)) +>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) + +class C6 extends Date { } +>C6 : Symbol(C6, Decl(classExtendingBuiltinType.ts, 4, 27)) +>Date : Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11)) + +class C7 extends RegExp { } +>C7 : Symbol(C7, Decl(classExtendingBuiltinType.ts, 5, 25)) +>RegExp : Symbol(RegExp, Decl(lib.d.ts, 825, 1), Decl(lib.d.ts, 876, 11)) + +class C8 extends Error { } +>C8 : Symbol(C8, Decl(classExtendingBuiltinType.ts, 6, 27)) +>Error : Symbol(Error, Decl(lib.d.ts, 876, 38), Decl(lib.d.ts, 889, 11)) + +class C9 extends Array { } +>C9 : Symbol(C9, Decl(classExtendingBuiltinType.ts, 7, 26)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11)) + +class C10 extends Array { } +>C10 : Symbol(C10, Decl(classExtendingBuiltinType.ts, 8, 26)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11)) + diff --git a/tests/baselines/reference/classExtendingBuiltinType.types b/tests/baselines/reference/classExtendingBuiltinType.types new file mode 100644 index 00000000000..ce774c0bff0 --- /dev/null +++ b/tests/baselines/reference/classExtendingBuiltinType.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/classes/classDeclarations/classExtendingBuiltinType.ts === +class C1 extends Object { } +>C1 : C1 +>Object : ObjectConstructor + +class C2 extends Function { } +>C2 : C2 +>Function : FunctionConstructor + +class C3 extends String { } +>C3 : C3 +>String : StringConstructor + +class C4 extends Boolean { } +>C4 : C4 +>Boolean : BooleanConstructor + +class C5 extends Number { } +>C5 : C5 +>Number : NumberConstructor + +class C6 extends Date { } +>C6 : C6 +>Date : DateConstructor + +class C7 extends RegExp { } +>C7 : C7 +>RegExp : RegExpConstructor + +class C8 extends Error { } +>C8 : C8 +>Error : ErrorConstructor + +class C9 extends Array { } +>C9 : C9 +>Array : ArrayConstructor + +class C10 extends Array { } +>C10 : C10 +>Array : ArrayConstructor + diff --git a/tests/baselines/reference/classExtendingClassLikeType.errors.txt b/tests/baselines/reference/classExtendingClassLikeType.errors.txt new file mode 100644 index 00000000000..6f9aef927ea --- /dev/null +++ b/tests/baselines/reference/classExtendingClassLikeType.errors.txt @@ -0,0 +1,70 @@ +tests/cases/conformance/classes/classDeclarations/classExtendingClassLikeType.ts(7,18): error TS2304: Cannot find name 'Base'. +tests/cases/conformance/classes/classDeclarations/classExtendingClassLikeType.ts(45,18): error TS2508: No base constructor has the specified number of type arguments. +tests/cases/conformance/classes/classDeclarations/classExtendingClassLikeType.ts(56,18): error TS2510: Base constructors must all have the same return type. + + +==== tests/cases/conformance/classes/classDeclarations/classExtendingClassLikeType.ts (3 errors) ==== + interface Base { + x: T; + y: U; + } + + // Error, no Base constructor function + class D0 extends Base { + ~~~~ +!!! error TS2304: Cannot find name 'Base'. + } + + interface BaseConstructor { + new (x: string, y: string): Base; + new (x: T): Base; + new (x: T, y: T): Base; + new (x: T, y: U): Base; + } + + declare function getBase(): BaseConstructor; + + class D1 extends getBase() { + constructor() { + super("abc", "def"); + this.x = "x"; + this.y = "y"; + } + } + + class D2 extends getBase() { + constructor() { + super(10); + super(10, 20); + this.x = 1; + this.y = 2; + } + } + + class D3 extends getBase() { + constructor() { + super("abc", 42); + this.x = "x"; + this.y = 2; + } + } + + // Error, no constructors with three type arguments + class D4 extends getBase() { + ~~~~~~~~~ +!!! error TS2508: No base constructor has the specified number of type arguments. + } + + interface BadBaseConstructor { + new (x: string): Base; + new (x: number): Base; + } + + declare function getBadBase(): BadBaseConstructor; + + // Error, constructor return types differ + class D5 extends getBadBase() { + ~~~~~~~~~~~~ +!!! error TS2510: Base constructors must all have the same return type. + } + \ No newline at end of file diff --git a/tests/baselines/reference/classExtendingClassLikeType.js b/tests/baselines/reference/classExtendingClassLikeType.js new file mode 100644 index 00000000000..88a5dc8dcd3 --- /dev/null +++ b/tests/baselines/reference/classExtendingClassLikeType.js @@ -0,0 +1,119 @@ +//// [classExtendingClassLikeType.ts] +interface Base { + x: T; + y: U; +} + +// Error, no Base constructor function +class D0 extends Base { +} + +interface BaseConstructor { + new (x: string, y: string): Base; + new (x: T): Base; + new (x: T, y: T): Base; + new (x: T, y: U): Base; +} + +declare function getBase(): BaseConstructor; + +class D1 extends getBase() { + constructor() { + super("abc", "def"); + this.x = "x"; + this.y = "y"; + } +} + +class D2 extends getBase() { + constructor() { + super(10); + super(10, 20); + this.x = 1; + this.y = 2; + } +} + +class D3 extends getBase() { + constructor() { + super("abc", 42); + this.x = "x"; + this.y = 2; + } +} + +// Error, no constructors with three type arguments +class D4 extends getBase() { +} + +interface BadBaseConstructor { + new (x: string): Base; + new (x: number): Base; +} + +declare function getBadBase(): BadBaseConstructor; + +// Error, constructor return types differ +class D5 extends getBadBase() { +} + + +//// [classExtendingClassLikeType.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +// Error, no Base constructor function +var D0 = (function (_super) { + __extends(D0, _super); + function D0() { + _super.apply(this, arguments); + } + return D0; +})(Base); +var D1 = (function (_super) { + __extends(D1, _super); + function D1() { + _super.call(this, "abc", "def"); + this.x = "x"; + this.y = "y"; + } + return D1; +})(getBase()); +var D2 = (function (_super) { + __extends(D2, _super); + function D2() { + _super.call(this, 10); + _super.call(this, 10, 20); + this.x = 1; + this.y = 2; + } + return D2; +})(getBase()); +var D3 = (function (_super) { + __extends(D3, _super); + function D3() { + _super.call(this, "abc", 42); + this.x = "x"; + this.y = 2; + } + return D3; +})(getBase()); +// Error, no constructors with three type arguments +var D4 = (function (_super) { + __extends(D4, _super); + function D4() { + _super.apply(this, arguments); + } + return D4; +})(getBase()); +// Error, constructor return types differ +var D5 = (function (_super) { + __extends(D5, _super); + function D5() { + _super.apply(this, arguments); + } + return D5; +})(getBadBase()); diff --git a/tests/baselines/reference/classExtendingNonConstructor.errors.txt b/tests/baselines/reference/classExtendingNonConstructor.errors.txt new file mode 100644 index 00000000000..b1e3994cf1c --- /dev/null +++ b/tests/baselines/reference/classExtendingNonConstructor.errors.txt @@ -0,0 +1,38 @@ +tests/cases/conformance/classes/classDeclarations/classExtendingNonConstructor.ts(7,18): error TS2507: Base expression is not of a constructor function type. +tests/cases/conformance/classes/classDeclarations/classExtendingNonConstructor.ts(8,18): error TS2507: Base expression is not of a constructor function type. +tests/cases/conformance/classes/classDeclarations/classExtendingNonConstructor.ts(9,18): error TS2507: Base expression is not of a constructor function type. +tests/cases/conformance/classes/classDeclarations/classExtendingNonConstructor.ts(10,18): error TS2507: Base expression is not of a constructor function type. +tests/cases/conformance/classes/classDeclarations/classExtendingNonConstructor.ts(11,18): error TS2507: Base expression is not of a constructor function type. +tests/cases/conformance/classes/classDeclarations/classExtendingNonConstructor.ts(12,18): error TS2507: Base expression is not of a constructor function type. +tests/cases/conformance/classes/classDeclarations/classExtendingNonConstructor.ts(13,18): error TS2507: Base expression is not of a constructor function type. + + +==== tests/cases/conformance/classes/classDeclarations/classExtendingNonConstructor.ts (7 errors) ==== + var x: {}; + + function foo() { + this.x = 1; + } + + class C1 extends undefined { } + ~~~~~~~~~ +!!! error TS2507: Base expression is not of a constructor function type. + class C2 extends true { } + ~~~~ +!!! error TS2507: Base expression is not of a constructor function type. + class C3 extends false { } + ~~~~~ +!!! error TS2507: Base expression is not of a constructor function type. + class C4 extends 42 { } + ~~ +!!! error TS2507: Base expression is not of a constructor function type. + class C5 extends "hello" { } + ~~~~~~~ +!!! error TS2507: Base expression is not of a constructor function type. + class C6 extends x { } + ~ +!!! error TS2507: Base expression is not of a constructor function type. + class C7 extends foo { } + ~~~ +!!! error TS2507: Base expression is not of a constructor function type. + \ No newline at end of file diff --git a/tests/baselines/reference/classExtendingNonConstructor.js b/tests/baselines/reference/classExtendingNonConstructor.js new file mode 100644 index 00000000000..f796b30ddd6 --- /dev/null +++ b/tests/baselines/reference/classExtendingNonConstructor.js @@ -0,0 +1,76 @@ +//// [classExtendingNonConstructor.ts] +var x: {}; + +function foo() { + this.x = 1; +} + +class C1 extends undefined { } +class C2 extends true { } +class C3 extends false { } +class C4 extends 42 { } +class C5 extends "hello" { } +class C6 extends x { } +class C7 extends foo { } + + +//// [classExtendingNonConstructor.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var x; +function foo() { + this.x = 1; +} +var C1 = (function (_super) { + __extends(C1, _super); + function C1() { + _super.apply(this, arguments); + } + return C1; +})(undefined); +var C2 = (function (_super) { + __extends(C2, _super); + function C2() { + _super.apply(this, arguments); + } + return C2; +})(true); +var C3 = (function (_super) { + __extends(C3, _super); + function C3() { + _super.apply(this, arguments); + } + return C3; +})(false); +var C4 = (function (_super) { + __extends(C4, _super); + function C4() { + _super.apply(this, arguments); + } + return C4; +})(42); +var C5 = (function (_super) { + __extends(C5, _super); + function C5() { + _super.apply(this, arguments); + } + return C5; +})("hello"); +var C6 = (function (_super) { + __extends(C6, _super); + function C6() { + _super.apply(this, arguments); + } + return C6; +})(x); +var C7 = (function (_super) { + __extends(C7, _super); + function C7() { + _super.apply(this, arguments); + } + return C7; +})(foo); diff --git a/tests/baselines/reference/classExtendingNull.js b/tests/baselines/reference/classExtendingNull.js new file mode 100644 index 00000000000..f0c3ea69626 --- /dev/null +++ b/tests/baselines/reference/classExtendingNull.js @@ -0,0 +1,26 @@ +//// [classExtendingNull.ts] +class C1 extends null { } +class C2 extends (null) { } + + +//// [classExtendingNull.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var C1 = (function (_super) { + __extends(C1, _super); + function C1() { + _super.apply(this, arguments); + } + return C1; +})(null); +var C2 = (function (_super) { + __extends(C2, _super); + function C2() { + _super.apply(this, arguments); + } + return C2; +})((null)); diff --git a/tests/baselines/reference/classExtendingNull.symbols b/tests/baselines/reference/classExtendingNull.symbols new file mode 100644 index 00000000000..37a6162f414 --- /dev/null +++ b/tests/baselines/reference/classExtendingNull.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/classes/classDeclarations/classExtendingNull.ts === +class C1 extends null { } +>C1 : Symbol(C1, Decl(classExtendingNull.ts, 0, 0)) + +class C2 extends (null) { } +>C2 : Symbol(C2, Decl(classExtendingNull.ts, 0, 25)) + diff --git a/tests/baselines/reference/classExtendingNull.types b/tests/baselines/reference/classExtendingNull.types new file mode 100644 index 00000000000..3c572a3406c --- /dev/null +++ b/tests/baselines/reference/classExtendingNull.types @@ -0,0 +1,10 @@ +=== tests/cases/conformance/classes/classDeclarations/classExtendingNull.ts === +class C1 extends null { } +>C1 : C1 +>null : null + +class C2 extends (null) { } +>C2 : C2 +>(null) : null +>null : null +