From 86b3c14099464ec43aabb961296f9098480766f6 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 1 Feb 2017 11:36:33 -0800 Subject: [PATCH 1/4] Consider 'object' a valid base type + apparent type of 'object' is {} --- src/compiler/checker.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index de7e9a9387f6a..b5306771dd7f7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3991,7 +3991,7 @@ namespace ts { // A valid base type is any non-generic object type or intersection of non-generic // object types. function isValidBaseType(type: Type): boolean { - return type.flags & TypeFlags.Object && !isGenericMappedType(type) || + return type.flags & (TypeFlags.Object | TypeFlags.NonPrimitive) && !isGenericMappedType(type) || type.flags & TypeFlags.Intersection && !forEach((type).types, t => !isValidBaseType(t)); } @@ -4944,7 +4944,7 @@ namespace ts { t.flags & TypeFlags.NumberLike ? globalNumberType : t.flags & TypeFlags.BooleanLike ? globalBooleanType : t.flags & TypeFlags.ESSymbol ? getGlobalESSymbolType() : - t.flags & TypeFlags.NonPrimitive ? globalObjectType : + t.flags & TypeFlags.NonPrimitive ? emptyObjectType : t; } From b6d612980c76f545d75cf669336457a33b85dec6 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 1 Feb 2017 11:37:11 -0800 Subject: [PATCH 2/4] Accept baseline change for apparent type --- tests/baselines/reference/nonPrimitiveAssignError.errors.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/nonPrimitiveAssignError.errors.txt b/tests/baselines/reference/nonPrimitiveAssignError.errors.txt index a9bfaaa4a8a4c..f8c4450f3aaa6 100644 --- a/tests/baselines/reference/nonPrimitiveAssignError.errors.txt +++ b/tests/baselines/reference/nonPrimitiveAssignError.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveAssignError.ts(5,1): error TS2322: Type 'object' is not assignable to type '{ foo: string; }'. - Property 'foo' is missing in type 'Object'. + Property 'foo' is missing in type '{}'. tests/cases/conformance/types/nonPrimitive/nonPrimitiveAssignError.ts(13,1): error TS2322: Type 'number' is not assignable to type 'object'. tests/cases/conformance/types/nonPrimitive/nonPrimitiveAssignError.ts(14,1): error TS2322: Type 'true' is not assignable to type 'object'. tests/cases/conformance/types/nonPrimitive/nonPrimitiveAssignError.ts(15,1): error TS2322: Type 'string' is not assignable to type 'object'. @@ -16,7 +16,7 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveAssignError.ts(19,1): err y = a; // expect error ~ !!! error TS2322: Type 'object' is not assignable to type '{ foo: string; }'. -!!! error TS2322: Property 'foo' is missing in type 'Object'. +!!! error TS2322: Property 'foo' is missing in type '{}'. a = x; a = y; From a8de5ce836e54c4d8d3713a6db789b27402c399c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 1 Feb 2017 11:37:24 -0800 Subject: [PATCH 3/4] Add regression test --- tests/cases/conformance/classes/mixinClassesAnonymous.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/cases/conformance/classes/mixinClassesAnonymous.ts b/tests/cases/conformance/classes/mixinClassesAnonymous.ts index 24289b61e3eb7..0e42288808762 100644 --- a/tests/cases/conformance/classes/mixinClassesAnonymous.ts +++ b/tests/cases/conformance/classes/mixinClassesAnonymous.ts @@ -54,3 +54,11 @@ class Thing3 extends Thing2 { this.print(); } } + +// Repro from #13805 + +const Timestamped = >(Base: CT) => { + return class extends Base { + timestamp = new Date(); + }; +} From 3a0a58d2e2274408788ff98246b001b176710617 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 1 Feb 2017 11:37:33 -0800 Subject: [PATCH 4/4] Accept new baselines --- .../reference/mixinClassesAnonymous.js | 20 +++++++++++++++++ .../reference/mixinClassesAnonymous.symbols | 19 ++++++++++++++++ .../reference/mixinClassesAnonymous.types | 22 +++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/tests/baselines/reference/mixinClassesAnonymous.js b/tests/baselines/reference/mixinClassesAnonymous.js index c7b8ab5fd63a2..aa148c25acf0d 100644 --- a/tests/baselines/reference/mixinClassesAnonymous.js +++ b/tests/baselines/reference/mixinClassesAnonymous.js @@ -55,6 +55,14 @@ class Thing3 extends Thing2 { this.print(); } } + +// Repro from #13805 + +const Timestamped = >(Base: CT) => { + return class extends Base { + timestamp = new Date(); + }; +} //// [mixinClassesAnonymous.js] @@ -138,3 +146,15 @@ var Thing3 = (function (_super) { }; return Thing3; }(Thing2)); +// Repro from #13805 +var Timestamped = function (Base) { + return (function (_super) { + __extends(class_2, _super); + function class_2() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.timestamp = new Date(); + return _this; + } + return class_2; + }(Base)); +}; diff --git a/tests/baselines/reference/mixinClassesAnonymous.symbols b/tests/baselines/reference/mixinClassesAnonymous.symbols index 204d9c589fda9..bd709501f3106 100644 --- a/tests/baselines/reference/mixinClassesAnonymous.symbols +++ b/tests/baselines/reference/mixinClassesAnonymous.symbols @@ -167,3 +167,22 @@ class Thing3 extends Thing2 { } } +// Repro from #13805 + +const Timestamped = >(Base: CT) => { +>Timestamped : Symbol(Timestamped, Decl(mixinClassesAnonymous.ts, 59, 5)) +>CT : Symbol(CT, Decl(mixinClassesAnonymous.ts, 59, 21)) +>Constructor : Symbol(Constructor, Decl(mixinClassesAnonymous.ts, 0, 0)) +>Base : Symbol(Base, Decl(mixinClassesAnonymous.ts, 59, 53)) +>CT : Symbol(CT, Decl(mixinClassesAnonymous.ts, 59, 21)) + + return class extends Base { +>Base : Symbol(Base, Decl(mixinClassesAnonymous.ts, 59, 53)) + + timestamp = new Date(); +>timestamp : Symbol((Anonymous class).timestamp, Decl(mixinClassesAnonymous.ts, 60, 31)) +>Date : Symbol(Date, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) + + }; +} + diff --git a/tests/baselines/reference/mixinClassesAnonymous.types b/tests/baselines/reference/mixinClassesAnonymous.types index 54b1c2c3819b7..516b15af2f351 100644 --- a/tests/baselines/reference/mixinClassesAnonymous.types +++ b/tests/baselines/reference/mixinClassesAnonymous.types @@ -198,3 +198,25 @@ class Thing3 extends Thing2 { } } +// Repro from #13805 + +const Timestamped = >(Base: CT) => { +>Timestamped : >(Base: CT) => { new (...args: any[]): (Anonymous class); prototype: .(Anonymous class); } & CT +>>(Base: CT) => { return class extends Base { timestamp = new Date(); };} : >(Base: CT) => { new (...args: any[]): (Anonymous class); prototype: .(Anonymous class); } & CT +>CT : CT +>Constructor : Constructor +>Base : CT +>CT : CT + + return class extends Base { +>class extends Base { timestamp = new Date(); } : { new (...args: any[]): (Anonymous class); prototype: .(Anonymous class); } & CT +>Base : object + + timestamp = new Date(); +>timestamp : Date +>new Date() : Date +>Date : DateConstructor + + }; +} +