Skip to content

Convert UnionOrIntersectionType.couldContainTypeVariables to ObjectFlags #36947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17740,18 +17740,18 @@ namespace ts {
// results for union and intersection types for performance reasons.
function couldContainTypeVariables(type: Type): boolean {
const objectFlags = getObjectFlags(type);
return !!(type.flags & TypeFlags.Instantiable ||
if (objectFlags & ObjectFlags.CouldContainTypeVariablesComputed) {
return !!(objectFlags & ObjectFlags.CouldContainTypeVariables);
}
const result = !!(type.flags & TypeFlags.Instantiable ||
objectFlags & ObjectFlags.Reference && ((<TypeReference>type).node || forEach(getTypeArguments(<TypeReference>type), couldContainTypeVariables)) ||
objectFlags & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.Class | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral) && type.symbol.declarations ||
objectFlags & (ObjectFlags.Mapped | ObjectFlags.ObjectRestType) ||
type.flags & TypeFlags.UnionOrIntersection && !(type.flags & TypeFlags.EnumLiteral) && couldUnionOrIntersectionContainTypeVariables(<UnionOrIntersectionType>type));
}

function couldUnionOrIntersectionContainTypeVariables(type: UnionOrIntersectionType): boolean {
if (type.couldContainTypeVariables === undefined) {
type.couldContainTypeVariables = some(type.types, couldContainTypeVariables);
type.flags & TypeFlags.UnionOrIntersection && !(type.flags & TypeFlags.EnumLiteral) && some((<UnionOrIntersectionType>type).types, couldContainTypeVariables));
if (type.flags & TypeFlags.ObjectFlagsType) {
(<ObjectFlagsType>type).objectFlags |= ObjectFlags.CouldContainTypeVariablesComputed | (result ? ObjectFlags.CouldContainTypeVariables : 0);
}
return type.couldContainTypeVariables;
return result;
}

function isTypeParameterAtTopLevel(type: Type, typeParameter: TypeParameter): boolean {
Expand Down
6 changes: 4 additions & 2 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4459,6 +4459,10 @@ namespace ts {
IsGenericIndexTypeComputed = 1 << 24, // IsGenericIndexType flag has been computed
/* @internal */
IsGenericIndexType = 1 << 25, // Union or intersection contains generic index type
/* @internal */
CouldContainTypeVariablesComputed = 1 << 26, // CouldContainTypeVariables flag has been computed
/* @internal */
CouldContainTypeVariables = 1 << 27, // Type could contain a type variable
ClassOrInterface = Class | Interface,
/* @internal */
RequiresWidening = ContainsWideningType | ContainsObjectOrArrayLiteral,
Expand Down Expand Up @@ -4577,8 +4581,6 @@ namespace ts {
resolvedStringIndexType: IndexType;
/* @internal */
resolvedBaseConstraint: Type;
/* @internal */
couldContainTypeVariables: boolean;
}

export interface UnionType extends UnionOrIntersectionType {
Expand Down