Make origin union cache key unique for key lists still under construction (#43339)

This commit is contained in:
Wesley Wigham 2021-04-05 11:47:49 -07:00 committed by GitHub
parent d1b43429c2
commit cf8798d977
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 143 additions and 1 deletions

View File

@ -13823,7 +13823,7 @@ namespace ts {
const typeKey = !origin ? getTypeListId(types) :
origin.flags & TypeFlags.Union ? `|${getTypeListId((<UnionType>origin).types)}` :
origin.flags & TypeFlags.Intersection ? `&${getTypeListId((<IntersectionType>origin).types)}` :
`#${(<IndexType>origin).type.id}`;
`#${(<IndexType>origin).type.id}|${getTypeListId(types)}`; // origin type id alone is insufficient, as `keyof x` may resolve to multiple WIP values while `x` is still resolving
const id = typeKey + getAliasId(aliasSymbol, aliasTypeArguments);
let type = unionTypes.get(id);
if (!type) {

View File

@ -0,0 +1,56 @@
//// [keyofGenericExtendingClassDoubleLayer.ts]
class Model<Attributes = any> {
public createdAt: Date;
}
type ModelAttributes<T> = Omit<T, keyof Model>;
class AutoModel<T> extends Model<ModelAttributes<T>> {}
class PersonModel extends AutoModel<PersonModel> {
public age: number;
toJson() {
let x: keyof this = 'createdAt';
}
}
//// [keyofGenericExtendingClassDoubleLayer.js]
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var Model = /** @class */ (function () {
function Model() {
}
return Model;
}());
var AutoModel = /** @class */ (function (_super) {
__extends(AutoModel, _super);
function AutoModel() {
return _super !== null && _super.apply(this, arguments) || this;
}
return AutoModel;
}(Model));
var PersonModel = /** @class */ (function (_super) {
__extends(PersonModel, _super);
function PersonModel() {
return _super !== null && _super.apply(this, arguments) || this;
}
PersonModel.prototype.toJson = function () {
var x = 'createdAt';
};
return PersonModel;
}(AutoModel));

View File

@ -0,0 +1,40 @@
=== tests/cases/compiler/keyofGenericExtendingClassDoubleLayer.ts ===
class Model<Attributes = any> {
>Model : Symbol(Model, Decl(keyofGenericExtendingClassDoubleLayer.ts, 0, 0))
>Attributes : Symbol(Attributes, Decl(keyofGenericExtendingClassDoubleLayer.ts, 0, 12))
public createdAt: Date;
>createdAt : Symbol(Model.createdAt, Decl(keyofGenericExtendingClassDoubleLayer.ts, 0, 31))
>Date : Symbol(Date, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.scripthost.d.ts, --, --))
}
type ModelAttributes<T> = Omit<T, keyof Model>;
>ModelAttributes : Symbol(ModelAttributes, Decl(keyofGenericExtendingClassDoubleLayer.ts, 2, 1))
>T : Symbol(T, Decl(keyofGenericExtendingClassDoubleLayer.ts, 4, 21))
>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --))
>T : Symbol(T, Decl(keyofGenericExtendingClassDoubleLayer.ts, 4, 21))
>Model : Symbol(Model, Decl(keyofGenericExtendingClassDoubleLayer.ts, 0, 0))
class AutoModel<T> extends Model<ModelAttributes<T>> {}
>AutoModel : Symbol(AutoModel, Decl(keyofGenericExtendingClassDoubleLayer.ts, 4, 47))
>T : Symbol(T, Decl(keyofGenericExtendingClassDoubleLayer.ts, 6, 16))
>Model : Symbol(Model, Decl(keyofGenericExtendingClassDoubleLayer.ts, 0, 0))
>ModelAttributes : Symbol(ModelAttributes, Decl(keyofGenericExtendingClassDoubleLayer.ts, 2, 1))
>T : Symbol(T, Decl(keyofGenericExtendingClassDoubleLayer.ts, 6, 16))
class PersonModel extends AutoModel<PersonModel> {
>PersonModel : Symbol(PersonModel, Decl(keyofGenericExtendingClassDoubleLayer.ts, 6, 55))
>AutoModel : Symbol(AutoModel, Decl(keyofGenericExtendingClassDoubleLayer.ts, 4, 47))
>PersonModel : Symbol(PersonModel, Decl(keyofGenericExtendingClassDoubleLayer.ts, 6, 55))
public age: number;
>age : Symbol(PersonModel.age, Decl(keyofGenericExtendingClassDoubleLayer.ts, 8, 50))
toJson() {
>toJson : Symbol(PersonModel.toJson, Decl(keyofGenericExtendingClassDoubleLayer.ts, 9, 23))
let x: keyof this = 'createdAt';
>x : Symbol(x, Decl(keyofGenericExtendingClassDoubleLayer.ts, 12, 11))
}
}

View File

@ -0,0 +1,31 @@
=== tests/cases/compiler/keyofGenericExtendingClassDoubleLayer.ts ===
class Model<Attributes = any> {
>Model : Model<Attributes>
public createdAt: Date;
>createdAt : Date
}
type ModelAttributes<T> = Omit<T, keyof Model>;
>ModelAttributes : ModelAttributes<T>
class AutoModel<T> extends Model<ModelAttributes<T>> {}
>AutoModel : AutoModel<T>
>Model : Model<ModelAttributes<T>>
class PersonModel extends AutoModel<PersonModel> {
>PersonModel : PersonModel
>AutoModel : AutoModel<PersonModel>
public age: number;
>age : number
toJson() {
>toJson : () => void
let x: keyof this = 'createdAt';
>x : keyof this
>'createdAt' : "createdAt"
}
}

View File

@ -0,0 +1,15 @@
class Model<Attributes = any> {
public createdAt: Date;
}
type ModelAttributes<T> = Omit<T, keyof Model>;
class AutoModel<T> extends Model<ModelAttributes<T>> {}
class PersonModel extends AutoModel<PersonModel> {
public age: number;
toJson() {
let x: keyof this = 'createdAt';
}
}