Skip to content

Commit d1641d8

Browse files
Converted some more locations, one more time
1 parent f2a2db1 commit d1641d8

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

src/compiler/checker.ts

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11959,8 +11959,8 @@ namespace ts {
1195911959

1196011960
function getPropertiesOfType(type: Type): Symbol[] {
1196111961
type = getReducedApparentType(type);
11962-
return type.flags & TypeFlags.UnionOrIntersection ?
11963-
getPropertiesOfUnionOrIntersectionType(type as UnionType) :
11962+
return isUnionOrIntersectionType(type) ?
11963+
getPropertiesOfUnionOrIntersectionType(type) :
1196411964
getPropertiesOfObjectType(type);
1196511965
}
1196611966

@@ -12712,7 +12712,7 @@ namespace ts {
1271212712
// signature applies to types assignable to 'number', `${number}` and numeric string literal types.
1271312713
return isTypeAssignableTo(source, target) ||
1271412714
target === stringType && isTypeAssignableTo(source, numberType) ||
12715-
target === numberType && (source === numericStringType || !!(source.flags & TypeFlags.StringLiteral) && isNumericLiteralName((source as StringLiteralType).value));
12715+
target === numberType && (source === numericStringType || isStringLiteralType(source) && isNumericLiteralName(source.value));
1271612716
}
1271712717

1271812718
function getIndexInfosOfStructuredType(type: Type): readonly IndexInfo[] {
@@ -15436,7 +15436,7 @@ namespace ts {
1543615436
}
1543715437

1543815438
function getTemplateStringForType(type: Type) {
15439-
return type.flags & TypeFlags.StringLiteral ? (type as StringLiteralType).value :
15439+
return isStringLiteralType(type) ? type.value :
1544015440
isNumberLiteralType(type) ? "" + type.value :
1544115441
isBigIntLiteralType(type) ? pseudoBigIntToString(type.value) :
1544215442
type.flags & (TypeFlags.BooleanLiteral | TypeFlags.Nullable) ? (type as IntrinsicType).intrinsicName :
@@ -15736,11 +15736,11 @@ namespace ts {
1573615736
}
1573715737

1573815738
function isPatternLiteralPlaceholderType(type: Type): boolean {
15739-
return !!(type.flags & (TypeFlags.Any | TypeFlags.String | TypeFlags.Number | TypeFlags.BigInt)) || !!(type.flags & TypeFlags.StringMapping && isPatternLiteralPlaceholderType((type as StringMappingType).type));
15739+
return !!(type.flags & (TypeFlags.Any | TypeFlags.String | TypeFlags.Number | TypeFlags.BigInt)) || !!(isStringMappingType(type) && isPatternLiteralPlaceholderType(type.type));
1574015740
}
1574115741

1574215742
function isPatternLiteralType(type: Type) {
15743-
return !!(type.flags & TypeFlags.TemplateLiteral) && every((type as TemplateLiteralType).types, isPatternLiteralPlaceholderType);
15743+
return isTemplateLiteralType(type) && every(type.types, isPatternLiteralPlaceholderType);
1574415744
}
1574515745

1574615746
function isGenericType(type: Type): boolean {
@@ -15793,8 +15793,8 @@ namespace ts {
1579315793
function distributeObjectOverIndexType(objectType: Type, indexType: Type, writing: boolean) {
1579415794
// T[A | B] -> T[A] | T[B] (reading)
1579515795
// T[A | B] -> T[A] & T[B] (writing)
15796-
if (indexType.flags & TypeFlags.Union) {
15797-
const types = map((indexType as UnionType).types, t => getSimplifiedType(getIndexedAccessType(objectType, t), writing));
15796+
if (isUnionType(indexType)) {
15797+
const types = map(indexType.types, t => getSimplifiedType(getIndexedAccessType(objectType, t), writing));
1579815798
return writing ? getIntersectionType(types) : getUnionType(types);
1579915799
}
1580015800
}
@@ -15945,10 +15945,10 @@ namespace ts {
1594515945
// We treat boolean as different from other unions to improve errors;
1594615946
// skipping straight to getPropertyTypeForIndexType gives errors with 'boolean' instead of 'true'.
1594715947
const apparentObjectType = getReducedApparentType(objectType);
15948-
if (indexType.flags & TypeFlags.Union && !(indexType.flags & TypeFlags.Boolean)) {
15948+
if (isUnionType(indexType) && !(indexType.flags & TypeFlags.Boolean)) {
1594915949
const propTypes: Type[] = [];
1595015950
let wasMissingProp = false;
15951-
for (const t of (indexType as UnionType).types) {
15951+
for (const t of indexType.types) {
1595215952
const propType = getPropertyTypeForIndexType(objectType, apparentObjectType, t, indexType, accessNode, accessFlags | (wasMissingProp ? AccessFlags.SuppressNoImplicitAnyError : 0));
1595315953
if (propType) {
1595415954
propTypes.push(propType);
@@ -16383,17 +16383,17 @@ namespace ts {
1638316383
}
1638416384

1638516385
function tryMergeUnionOfObjectTypeAndEmptyObject(type: Type, readonly: boolean): Type {
16386-
if (!(type.flags & TypeFlags.Union)) {
16386+
if (!isUnionType(type)) {
1638716387
return type;
1638816388
}
16389-
if (every((type as UnionType).types, isEmptyObjectTypeOrSpreadsIntoEmptyObject)) {
16390-
return find((type as UnionType).types, isEmptyObjectType) || emptyObjectType;
16389+
if (every(type.types, isEmptyObjectTypeOrSpreadsIntoEmptyObject)) {
16390+
return find(type.types, isEmptyObjectType) || emptyObjectType;
1639116391
}
16392-
const firstType = find((type as UnionType).types, t => !isEmptyObjectTypeOrSpreadsIntoEmptyObject(t));
16392+
const firstType = find(type.types, t => !isEmptyObjectTypeOrSpreadsIntoEmptyObject(t));
1639316393
if (!firstType) {
1639416394
return type;
1639516395
}
16396-
const secondType = find((type as UnionType).types, t => t !== firstType && !isEmptyObjectTypeOrSpreadsIntoEmptyObject(t));
16396+
const secondType = find(type.types, t => t !== firstType && !isEmptyObjectTypeOrSpreadsIntoEmptyObject(t));
1639716397
if (secondType) {
1639816398
return type;
1639916399
}
@@ -16563,7 +16563,7 @@ namespace ts {
1656316563

1656416564
function getRegularTypeOfLiteralType(type: Type): Type {
1656516565
return type.flags & TypeFlags.Literal ? (type as LiteralType).regularType :
16566-
type.flags & TypeFlags.Union ? ((type as UnionType).regularType || ((type as UnionType).regularType = mapType(type, getRegularTypeOfLiteralType) as UnionType)) :
16566+
isUnionType(type) ? (type.regularType || (type.regularType = mapType(type, getRegularTypeOfLiteralType) as UnionType)) :
1656716567
type;
1656816568
}
1656916569

@@ -22062,10 +22062,10 @@ namespace ts {
2206222062
function createEmptyObjectTypeFromStringLiteral(type: Type) {
2206322063
const members = createSymbolTable();
2206422064
forEachType(type, t => {
22065-
if (!(t.flags & TypeFlags.StringLiteral)) {
22065+
if (!isStringLiteralType(t)) {
2206622066
return;
2206722067
}
22068-
const name = escapeLeadingUnderscores((t as StringLiteralType).value);
22068+
const name = escapeLeadingUnderscores(t.value);
2206922069
const literalProp = createSymbol(SymbolFlags.Property, name);
2207022070
literalProp.type = anyType;
2207122071
if (t.symbol) {
@@ -22274,7 +22274,7 @@ namespace ts {
2227422274
if (target.flags & TypeFlags.TemplateLiteral) {
2227522275
return isTypeAssignableTo(source, target);
2227622276
}
22277-
if (target.flags & TypeFlags.StringMapping) {
22277+
if (isStringMappingType(target)) {
2227822278
// We need to see whether applying the same mappings of the target
2227922279
// onto the source would produce an identical type *and* that
2228022280
// it's compatible with the inner-most non-string-mapped type.
@@ -22283,9 +22283,9 @@ namespace ts {
2228322283
// and the source is compatible with the unmapped target, then they must
2228422284
// still reside in the same domain.
2228522285
const mappingStack = [];
22286-
while (target.flags & TypeFlags.StringMapping) {
22286+
while (isStringMappingType(target)) {
2228722287
mappingStack.unshift(target.symbol);
22288-
target = (target as StringMappingType).type;
22288+
target = target.type;
2228922289
}
2229022290
const mappedSource = reduceLeft(mappingStack, (memo, value) => getStringMappingType(value, memo), source);
2229122291
return mappedSource === source && isMemberOfStringMapping(source, target);
@@ -22902,16 +22902,16 @@ namespace ts {
2290222902

2290322903
// If we are inferring from a string literal type to a type variable whose constraint includes one of the
2290422904
// allowed template literal placeholder types, infer from a literal type corresponding to the constraint.
22905-
if (source.flags & TypeFlags.StringLiteral && target.flags & TypeFlags.TypeVariable) {
22905+
if (isStringLiteralType(source) && target.flags & TypeFlags.TypeVariable) {
2290622906
const inferenceContext = getInferenceInfoForType(target);
2290722907
const constraint = inferenceContext ? getBaseConstraintOfType(inferenceContext.typeParameter) : undefined;
2290822908
if (constraint && !isTypeAny(constraint)) {
22909-
const constraintTypes = constraint.flags & TypeFlags.Union ? (constraint as UnionType).types : [constraint];
22909+
const constraintTypes = isUnionType(constraint) ? constraint.types : [constraint];
2291022910
let allTypeFlags: TypeFlags = reduceLeft(constraintTypes, (flags, t) => flags | t.flags, 0 as TypeFlags);
2291122911

2291222912
// If the constraint contains `string`, we don't need to look for a more preferred type
2291322913
if (!(allTypeFlags & TypeFlags.String)) {
22914-
const str = (source as StringLiteralType).value;
22914+
const str = source.value;
2291522915

2291622916
// If the type contains `number` or a number literal and the string isn't a valid number, exclude numbers
2291722917
if (allTypeFlags & TypeFlags.NumberLike && !isValidNumberString(str, /*roundTripOnly*/ true)) {
@@ -23662,7 +23662,7 @@ namespace ts {
2366223662
return strictNullChecks ? TypeFacts.StringStrictFacts : TypeFacts.StringFacts;
2366323663
}
2366423664
if (flags & (TypeFlags.StringLiteral | TypeFlags.TemplateLiteral)) {
23665-
const isEmpty = flags & TypeFlags.StringLiteral && (type as StringLiteralType).value === "";
23665+
const isEmpty = isStringLiteralType(type) && type.value === "";
2366623666
return strictNullChecks ?
2366723667
isEmpty ? TypeFacts.EmptyStringStrictFacts : TypeFacts.NonEmptyStringStrictFacts :
2366823668
isEmpty ? TypeFacts.EmptyStringFacts : TypeFacts.NonEmptyStringFacts;
@@ -24743,7 +24743,7 @@ namespace ts {
2474324743
}
2474424744
else if (expr.kind === SyntaxKind.TypeOfExpression && optionalChainContainsReference((expr as TypeOfExpression).expression, reference)) {
2474524745
type = narrowTypeBySwitchOptionalChainContainment(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd,
24746-
t => !(t.flags & TypeFlags.Never || t.flags & TypeFlags.StringLiteral && (t as StringLiteralType).value === "undefined"));
24746+
t => !(t.flags & TypeFlags.Never || isStringLiteralType(t) && t.value === "undefined"));
2474724747
}
2474824748
}
2474924749
const access = getDiscriminantPropertyAccess(expr, type);
@@ -25093,8 +25093,8 @@ namespace ts {
2509325093
}
2509425094
const target = getReferenceCandidate(expr.right);
2509525095
const leftType = getTypeOfNode(expr.left);
25096-
if (leftType.flags & TypeFlags.StringLiteral) {
25097-
const name = escapeLeadingUnderscores((leftType as StringLiteralType).value);
25096+
if (isStringLiteralType(leftType)) {
25097+
const name = escapeLeadingUnderscores(leftType.value);
2509825098
if (containsMissingType(type) && isAccessExpression(reference) && isMatchingReference(reference.expression, target) &&
2509925099
getAccessedPropertyName(reference) === name) {
2510025100
return getTypeWithFacts(type, assumeTrue ? TypeFacts.NEUndefined : TypeFacts.EQUndefined);
@@ -27483,8 +27483,8 @@ namespace ts {
2748327483
return getOrCreateTypeFromSignature(fakeSignature);
2748427484
}
2748527485
const tagType = checkExpressionCached(context.tagName);
27486-
if (tagType.flags & TypeFlags.StringLiteral) {
27487-
const result = getIntrinsicAttributesTypeFromStringLiteralType(tagType as StringLiteralType, context);
27486+
if (isStringLiteralType(tagType)) {
27487+
const result = getIntrinsicAttributesTypeFromStringLiteralType(tagType, context);
2748827488
if (!result) {
2748927489
return errorType;
2749027490
}
@@ -28548,10 +28548,10 @@ namespace ts {
2854828548
if (elementType.flags & TypeFlags.String) {
2854928549
return [anySignature];
2855028550
}
28551-
else if (elementType.flags & TypeFlags.StringLiteral) {
28552-
const intrinsicType = getIntrinsicAttributesTypeFromStringLiteralType(elementType as StringLiteralType, caller);
28551+
else if (isStringLiteralType(elementType)) {
28552+
const intrinsicType = getIntrinsicAttributesTypeFromStringLiteralType(elementType, caller);
2855328553
if (!intrinsicType) {
28554-
error(caller, Diagnostics.Property_0_does_not_exist_on_type_1, (elementType as StringLiteralType).value, "JSX." + JsxNames.IntrinsicElements);
28554+
error(caller, Diagnostics.Property_0_does_not_exist_on_type_1, elementType.value, "JSX." + JsxNames.IntrinsicElements);
2855528555
return emptyArray;
2855628556
}
2855728557
else {

0 commit comments

Comments
 (0)