Skip to content

Commit 411e714

Browse files
committed
Add new nonInferrableType with ObjectFlags.NonInferrableType
1 parent ef4acc8 commit 411e714

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

src/compiler/checker.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,10 @@ namespace ts {
404404
const wildcardType = createIntrinsicType(TypeFlags.Any, "any");
405405
const errorType = createIntrinsicType(TypeFlags.Any, "error");
406406
const unknownType = createIntrinsicType(TypeFlags.Unknown, "unknown");
407-
const undefinedType = createNullableType(TypeFlags.Undefined, "undefined", 0);
408-
const undefinedWideningType = strictNullChecks ? undefinedType : createNullableType(TypeFlags.Undefined, "undefined", ObjectFlags.ContainsWideningType);
409-
const nullType = createNullableType(TypeFlags.Null, "null", 0);
410-
const nullWideningType = strictNullChecks ? nullType : createNullableType(TypeFlags.Null, "null", ObjectFlags.ContainsWideningType);
407+
const undefinedType = createIntrinsicType(TypeFlags.Undefined, "undefined");
408+
const undefinedWideningType = strictNullChecks ? undefinedType : createIntrinsicType(TypeFlags.Undefined, "undefined", ObjectFlags.ContainsWideningType);
409+
const nullType = createIntrinsicType(TypeFlags.Null, "null");
410+
const nullWideningType = strictNullChecks ? nullType : createIntrinsicType(TypeFlags.Null, "null", ObjectFlags.ContainsWideningType);
411411
const stringType = createIntrinsicType(TypeFlags.String, "string");
412412
const numberType = createIntrinsicType(TypeFlags.Number, "number");
413413
const bigintType = createIntrinsicType(TypeFlags.BigInt, "bigint");
@@ -433,6 +433,7 @@ namespace ts {
433433
const voidType = createIntrinsicType(TypeFlags.Void, "void");
434434
const neverType = createIntrinsicType(TypeFlags.Never, "never");
435435
const silentNeverType = createIntrinsicType(TypeFlags.Never, "never");
436+
const nonInferrableType = createIntrinsicType(TypeFlags.Never, "never", ObjectFlags.NonInferrableType);
436437
const implicitNeverType = createIntrinsicType(TypeFlags.Never, "never");
437438
const nonPrimitiveType = createIntrinsicType(TypeFlags.NonPrimitive, "object");
438439
const stringNumberSymbolType = getUnionType([stringType, numberType, esSymbolType]);
@@ -453,7 +454,7 @@ namespace ts {
453454
const anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
454455
// The anyFunctionType contains the anyFunctionType by definition. The flag is further propagated
455456
// in getPropagatingFlagsOfTypes, and it is checked in inferFromTypes.
456-
anyFunctionType.objectFlags |= ObjectFlags.ContainsAnyFunctionType;
457+
anyFunctionType.objectFlags |= ObjectFlags.NonInferrableType;
457458

458459
const noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
459460
const circularConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
@@ -2797,14 +2798,9 @@ namespace ts {
27972798
return result;
27982799
}
27992800

2800-
function createIntrinsicType(kind: TypeFlags, intrinsicName: string): IntrinsicType {
2801+
function createIntrinsicType(kind: TypeFlags, intrinsicName: string, objectFlags: ObjectFlags = 0): IntrinsicType {
28012802
const type = <IntrinsicType>createType(kind);
28022803
type.intrinsicName = intrinsicName;
2803-
return type;
2804-
}
2805-
2806-
function createNullableType(kind: TypeFlags, intrinsicName: string, objectFlags: ObjectFlags): NullableType {
2807-
const type = createIntrinsicType(kind, intrinsicName);
28082804
type.objectFlags = objectFlags;
28092805
return type;
28102806
}
@@ -14513,7 +14509,7 @@ namespace ts {
1451314509
// If any property contains context sensitive functions that have been skipped, the source type
1451414510
// is incomplete and we can't infer a meaningful input type.
1451514511
for (const prop of properties) {
14516-
if (getObjectFlags(getTypeOfSymbol(prop)) & ObjectFlags.ContainsAnyFunctionType) {
14512+
if (getObjectFlags(getTypeOfSymbol(prop)) & ObjectFlags.NonInferrableType) {
1451714513
return undefined;
1451814514
}
1451914515
}
@@ -14670,7 +14666,7 @@ namespace ts {
1467014666
// not contain anyFunctionType when we come back to this argument for its second round
1467114667
// of inference. Also, we exclude inferences for silentNeverType (which is used as a wildcard
1467214668
// when constructing types from type parameters that had no inference candidates).
14673-
if (getObjectFlags(source) & ObjectFlags.ContainsAnyFunctionType || source === silentNeverType || (priority & InferencePriority.ReturnType && (source === autoType || source === autoArrayType))) {
14669+
if (getObjectFlags(source) & ObjectFlags.NonInferrableType || source === silentNeverType || (priority & InferencePriority.ReturnType && (source === autoType || source === autoArrayType))) {
1467414670
return;
1467514671
}
1467614672
const inference = getInferenceInfoForType(target);
@@ -14991,7 +14987,7 @@ namespace ts {
1499114987
const sourceLen = sourceSignatures.length;
1499214988
const targetLen = targetSignatures.length;
1499314989
const len = sourceLen < targetLen ? sourceLen : targetLen;
14994-
const skipParameters = !!(getObjectFlags(source) & ObjectFlags.ContainsAnyFunctionType);
14990+
const skipParameters = !!(getObjectFlags(source) & ObjectFlags.NonInferrableType);
1499514991
for (let i = 0; i < len; i++) {
1499614992
inferFromSignature(getBaseSignature(sourceSignatures[sourceLen - len + i]), getBaseSignature(targetSignatures[targetLen - len + i]), skipParameters);
1499714993
}
@@ -21120,7 +21116,7 @@ namespace ts {
2112021116
// returns a function type, we choose to defer processing. This narrowly permits function composition
2112121117
// operators to flow inferences through return types, but otherwise processes calls right away. We
2112221118
// use the resolvingSignature singleton to indicate that we deferred processing. This result will be
21123-
// propagated out and eventually turned into silentNeverType (a type that is assignable to anything and
21119+
// propagated out and eventually turned into nonInferrableType (a type that is assignable to anything and
2112421120
// from which we never make inferences).
2112521121
if (checkMode & CheckMode.SkipGenericFunctions && !node.typeArguments && callSignatures.some(isGenericFunctionReturningFunction)) {
2112621122
skippedGenericFunction(node, checkMode);
@@ -21603,8 +21599,8 @@ namespace ts {
2160321599
const signature = getResolvedSignature(node, /*candidatesOutArray*/ undefined, checkMode);
2160421600
if (signature === resolvingSignature) {
2160521601
// CheckMode.SkipGenericFunctions is enabled and this is a call to a generic function that
21606-
// returns a function type. We defer checking and return anyFunctionType.
21607-
return silentNeverType;
21602+
// returns a function type. We defer checking and return nonInferrableType.
21603+
return nonInferrableType;
2160821604
}
2160921605

2161021606
if (node.expression.kind === SyntaxKind.SuperKeyword) {
@@ -22411,7 +22407,7 @@ namespace ts {
2241122407
const returnType = getReturnTypeFromBody(node, checkMode);
2241222408
const returnOnlySignature = createSignature(undefined, undefined, undefined, emptyArray, returnType, /*resolvedTypePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
2241322409
const returnOnlyType = createAnonymousType(node.symbol, emptySymbols, [returnOnlySignature], emptyArray, undefined, undefined);
22414-
returnOnlyType.objectFlags |= ObjectFlags.ContainsAnyFunctionType;
22410+
returnOnlyType.objectFlags |= ObjectFlags.NonInferrableType;
2241522411
return links.contextFreeType = returnOnlyType;
2241622412
}
2241722413
return anyFunctionType;

src/compiler/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3944,7 +3944,7 @@ namespace ts {
39443944
Instantiable = InstantiableNonPrimitive | InstantiablePrimitive,
39453945
StructuredOrInstantiable = StructuredType | Instantiable,
39463946
/* @internal */
3947-
ObjectFlagsType = Nullable | Object | Union | Intersection,
3947+
ObjectFlagsType = Nullable | Never | Object | Union | Intersection,
39483948
// 'Narrowable' types are types where narrowing actually narrows.
39493949
// This *should* be every type other than null, undefined, void, and never
39503950
Narrowable = Any | Unknown | StructuredOrInstantiable | StringLike | NumberLike | BigIntLike | BooleanLike | ESSymbol | UniqueESSymbol | NonPrimitive,
@@ -4064,12 +4064,12 @@ namespace ts {
40644064
/* @internal */
40654065
ContainsObjectLiteral = 1 << 18, // Type is or contains object literal type
40664066
/* @internal */
4067-
ContainsAnyFunctionType = 1 << 19, // Type is or contains the anyFunctionType
4067+
NonInferrableType = 1 << 19, // Type is or contains anyFunctionType or silentNeverType
40684068
ClassOrInterface = Class | Interface,
40694069
/* @internal */
40704070
RequiresWidening = ContainsWideningType | ContainsObjectLiteral,
40714071
/* @internal */
4072-
PropagatingFlags = ContainsWideningType | ContainsObjectLiteral | ContainsAnyFunctionType
4072+
PropagatingFlags = ContainsWideningType | ContainsObjectLiteral | NonInferrableType
40734073
}
40744074

40754075
/* @internal */

0 commit comments

Comments
 (0)