Skip to content

Commit 4b8e8b7

Browse files
authored
Merge pull request #11212 from Microsoft/cleanup-TypeFlags
Turn 2 type flags into properties
2 parents adeb2a2 + f852696 commit 4b8e8b7

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/compiler/checker.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,7 +2165,7 @@ namespace ts {
21652165
? "any"
21662166
: (<IntrinsicType>type).intrinsicName);
21672167
}
2168-
else if (type.flags & TypeFlags.ThisType) {
2168+
else if (type.flags & TypeFlags.TypeParameter && (type as TypeParameter).isThisType) {
21692169
if (inObjectTypeLiteral) {
21702170
writer.reportInaccessibleThisError();
21712171
}
@@ -3179,7 +3179,7 @@ namespace ts {
31793179
result.pattern = pattern;
31803180
}
31813181
if (hasComputedProperties) {
3182-
result.flags |= TypeFlags.ObjectLiteralPatternWithComputedProperties;
3182+
result.isObjectLiteralPatternWithComputedProperties = true;
31833183
}
31843184
return result;
31853185
}
@@ -3766,7 +3766,8 @@ namespace ts {
37663766
(<GenericType>type).instantiations[getTypeListId(type.typeParameters)] = <GenericType>type;
37673767
(<GenericType>type).target = <GenericType>type;
37683768
(<GenericType>type).typeArguments = type.typeParameters;
3769-
type.thisType = <TypeParameter>createType(TypeFlags.TypeParameter | TypeFlags.ThisType);
3769+
type.thisType = <TypeParameter>createType(TypeFlags.TypeParameter);
3770+
type.thisType.isThisType = true;
37703771
type.thisType.symbol = symbol;
37713772
type.thisType.constraint = type;
37723773
}
@@ -4968,7 +4969,7 @@ namespace ts {
49684969

49694970
function hasConstraintReferenceTo(type: Type, target: TypeParameter): boolean {
49704971
let checked: Type[];
4971-
while (type && !(type.flags & TypeFlags.ThisType) && type.flags & TypeFlags.TypeParameter && !contains(checked, type)) {
4972+
while (type && type.flags & TypeFlags.TypeParameter && !((type as TypeParameter).isThisType) && !contains(checked, type)) {
49724973
if (type === target) {
49734974
return true;
49744975
}
@@ -5331,7 +5332,8 @@ namespace ts {
53315332
type.instantiations[getTypeListId(type.typeParameters)] = <GenericType>type;
53325333
type.target = <GenericType>type;
53335334
type.typeArguments = type.typeParameters;
5334-
type.thisType = <TypeParameter>createType(TypeFlags.TypeParameter | TypeFlags.ThisType);
5335+
type.thisType = <TypeParameter>createType(TypeFlags.TypeParameter);
5336+
type.thisType.isThisType = true;
53355337
type.thisType.constraint = type;
53365338
type.declaredProperties = properties;
53375339
type.declaredCallSignatures = emptyArray;
@@ -6647,7 +6649,8 @@ namespace ts {
66476649
}
66486650

66496651
function hasExcessProperties(source: FreshObjectLiteralType, target: Type, reportErrors: boolean): boolean {
6650-
if (!(target.flags & TypeFlags.ObjectLiteralPatternWithComputedProperties) && maybeTypeOfKind(target, TypeFlags.ObjectType)) {
6652+
if (maybeTypeOfKind(target, TypeFlags.ObjectType) &&
6653+
(!(target.flags & TypeFlags.ObjectType) || !(target as ObjectType).isObjectLiteralPatternWithComputedProperties)) {
66516654
for (const prop of getPropertiesOfObjectType(source)) {
66526655
if (!isKnownProperty(target, prop.name)) {
66536656
if (reportErrors) {
@@ -10307,7 +10310,8 @@ namespace ts {
1030710310
patternWithComputedProperties = true;
1030810311
}
1030910312
}
10310-
else if (contextualTypeHasPattern && !(contextualType.flags & TypeFlags.ObjectLiteralPatternWithComputedProperties)) {
10313+
else if (contextualTypeHasPattern &&
10314+
!(contextualType.flags & TypeFlags.ObjectType && (contextualType as ObjectType).isObjectLiteralPatternWithComputedProperties)) {
1031110315
// If object literal is contextually typed by the implied type of a binding pattern, and if the
1031210316
// binding pattern specifies a default value for the property, make the property optional.
1031310317
const impliedProp = getPropertyOfType(contextualType, member.name);
@@ -10372,7 +10376,10 @@ namespace ts {
1037210376
const numberIndexInfo = hasComputedNumberProperty ? getObjectLiteralIndexInfo(node, propertiesArray, IndexKind.Number) : undefined;
1037310377
const result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo);
1037410378
const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshLiteral;
10375-
result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | (typeFlags & TypeFlags.PropagatingFlags) | (patternWithComputedProperties ? TypeFlags.ObjectLiteralPatternWithComputedProperties : 0);
10379+
result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | (typeFlags & TypeFlags.PropagatingFlags);
10380+
if (patternWithComputedProperties) {
10381+
result.isObjectLiteralPatternWithComputedProperties = true;
10382+
}
1037610383
if (inDestructuringPattern) {
1037710384
result.pattern = node;
1037810385
}
@@ -10942,7 +10949,7 @@ namespace ts {
1094210949
return true;
1094310950
}
1094410951
// An instance property must be accessed through an instance of the enclosing class
10945-
if (type.flags & TypeFlags.ThisType) {
10952+
if (type.flags & TypeFlags.TypeParameter && (type as TypeParameter).isThisType) {
1094610953
// get the original type -- represented as the type constraint of the 'this' type
1094710954
type = getConstraintOfTypeParameter(<TypeParameter>type);
1094810955
}
@@ -10992,7 +10999,7 @@ namespace ts {
1099210999
const prop = getPropertyOfType(apparentType, right.text);
1099311000
if (!prop) {
1099411001
if (right.text && !checkAndReportErrorForExtendingInterface(node)) {
10995-
reportNonexistentProperty(right, type.flags & TypeFlags.ThisType ? apparentType : type);
11002+
reportNonexistentProperty(right, type.flags & TypeFlags.TypeParameter && (type as TypeParameter).isThisType ? apparentType : type);
1099611003
}
1099711004
return unknownType;
1099811005
}

src/compiler/types.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,8 +2393,6 @@ namespace ts {
23932393
ContainsObjectLiteral = 1 << 26, // Type is or contains object literal type
23942394
/* @internal */
23952395
ContainsAnyFunctionType = 1 << 27, // Type is or contains object literal type
2396-
ThisType = 1 << 28, // This type
2397-
ObjectLiteralPatternWithComputedProperties = 1 << 29, // Object literal type implied by binding pattern has computed properties
23982396

23992397
/* @internal */
24002398
Nullable = Undefined | Null,
@@ -2463,7 +2461,9 @@ namespace ts {
24632461
}
24642462

24652463
// Object types (TypeFlags.ObjectType)
2466-
export interface ObjectType extends Type { }
2464+
export interface ObjectType extends Type {
2465+
isObjectLiteralPatternWithComputedProperties?: boolean;
2466+
}
24672467

24682468
// Class and interface types (TypeFlags.Class and TypeFlags.Interface)
24692469
export interface InterfaceType extends ObjectType {
@@ -2558,6 +2558,8 @@ namespace ts {
25582558
mapper?: TypeMapper; // Instantiation mapper
25592559
/* @internal */
25602560
resolvedApparentType: Type;
2561+
/* @internal */
2562+
isThisType?: boolean;
25612563
}
25622564

25632565
export const enum SignatureKind {

0 commit comments

Comments
 (0)