@@ -7330,7 +7330,7 @@ namespace ts {
7330
7330
const declaredType = <MappedType>getTypeFromMappedTypeNode(type.declaration);
7331
7331
const constraint = getConstraintTypeFromMappedType(declaredType);
7332
7332
const extendedConstraint = constraint && constraint.flags & TypeFlags.TypeParameter ? getConstraintOfTypeParameter(<TypeParameter>constraint) : constraint;
7333
- type.modifiersType = extendedConstraint && extendedConstraint.flags & TypeFlags.Index ? instantiateType((<IndexType>extendedConstraint).type, type.mapper || identityMapper) : emptyObjectType ;
7333
+ type.modifiersType = extendedConstraint && extendedConstraint.flags & TypeFlags.Index ? instantiateType((<IndexType>extendedConstraint).type, type.mapper || identityMapper) : unknownType ;
7334
7334
}
7335
7335
}
7336
7336
return type.modifiersType;
@@ -7773,7 +7773,7 @@ namespace ts {
7773
7773
* type itself. Note that the apparent type of a union type is the union type itself.
7774
7774
*/
7775
7775
function getApparentType(type: Type): Type {
7776
- const t = type.flags & TypeFlags.Instantiable ? getBaseConstraintOfType(type) || emptyObjectType : type;
7776
+ const t = type.flags & TypeFlags.Instantiable ? getBaseConstraintOfType(type) || unknownType : type;
7777
7777
return getObjectFlags(t) & ObjectFlags.Mapped ? getApparentTypeOfMappedType(<MappedType>t) :
7778
7778
t.flags & TypeFlags.Intersection ? getApparentTypeOfIntersectionType(<IntersectionType>t) :
7779
7779
t.flags & TypeFlags.StringLike ? globalStringType :
@@ -7783,6 +7783,7 @@ namespace ts {
7783
7783
t.flags & TypeFlags.ESSymbolLike ? getGlobalESSymbolType(/*reportErrors*/ languageVersion >= ScriptTarget.ES2015) :
7784
7784
t.flags & TypeFlags.NonPrimitive ? emptyObjectType :
7785
7785
t.flags & TypeFlags.Index ? keyofConstraintType :
7786
+ t.flags & TypeFlags.Unknown && !strictNullChecks ? emptyObjectType :
7786
7787
t;
7787
7788
}
7788
7789
@@ -8106,7 +8107,7 @@ namespace ts {
8106
8107
const baseDefaultType = getDefaultTypeArgumentType(isJavaScriptImplicitAny);
8107
8108
for (let i = numTypeArguments; i < numTypeParameters; i++) {
8108
8109
let defaultType = getDefaultFromTypeParameter(typeParameters![i]);
8109
- if (isJavaScriptImplicitAny && defaultType && isTypeIdenticalTo(defaultType, emptyObjectType)) {
8110
+ if (isJavaScriptImplicitAny && defaultType && ( isTypeIdenticalTo(defaultType, unknownType) || isTypeIdenticalTo(defaultType, emptyObjectType) )) {
8110
8111
defaultType = anyType;
8111
8112
}
8112
8113
result[i] = defaultType ? instantiateType(defaultType, createTypeMapper(typeParameters!, result)) : baseDefaultType;
@@ -8485,7 +8486,7 @@ namespace ts {
8485
8486
const typeParameters = signature.typeParameters;
8486
8487
if (typeParameters) {
8487
8488
const typeEraser = createTypeEraser(typeParameters);
8488
- const baseConstraints = map(typeParameters, tp => instantiateType(getBaseConstraintOfType(tp), typeEraser) || emptyObjectType );
8489
+ const baseConstraints = map(typeParameters, tp => instantiateType(getBaseConstraintOfType(tp), typeEraser) || unknownType );
8489
8490
return instantiateSignature(signature, createTypeMapper(typeParameters, baseConstraints), /*eraseTypeParameters*/ true);
8490
8491
}
8491
8492
return signature;
@@ -10799,7 +10800,7 @@ namespace ts {
10799
10800
* This is used during inference when instantiating type parameter defaults.
10800
10801
*/
10801
10802
function createBackreferenceMapper(context: InferenceContext, index: number): TypeMapper {
10802
- return t => findIndex(context.inferences, info => info.typeParameter === t) >= index ? emptyObjectType : t;
10803
+ return t => findIndex(context.inferences, info => info.typeParameter === t) >= index ? unknownType : t;
10803
10804
}
10804
10805
10805
10806
function combineTypeMappers(mapper1: TypeMapper | undefined, mapper2: TypeMapper): TypeMapper;
@@ -11346,7 +11347,7 @@ namespace ts {
11346
11347
function isTypeDerivedFrom(source: Type, target: Type): boolean {
11347
11348
return source.flags & TypeFlags.Union ? every((<UnionType>source).types, t => isTypeDerivedFrom(t, target)) :
11348
11349
target.flags & TypeFlags.Union ? some((<UnionType>target).types, t => isTypeDerivedFrom(source, t)) :
11349
- source.flags & TypeFlags.InstantiableNonPrimitive ? isTypeDerivedFrom(getBaseConstraintOfType(source) || emptyObjectType , target) :
11350
+ source.flags & TypeFlags.InstantiableNonPrimitive ? isTypeDerivedFrom(getBaseConstraintOfType(source) || unknownType , target) :
11350
11351
target === globalObjectType ? !!(source.flags & (TypeFlags.Object | TypeFlags.NonPrimitive)) :
11351
11352
target === globalFunctionType ? !!(source.flags & TypeFlags.Object) && isFunctionObjectType(source as ObjectType) :
11352
11353
hasBaseType(source, getTargetType(target));
@@ -13349,7 +13350,7 @@ namespace ts {
13349
13350
return indexTypesIdenticalTo(source, target, kind);
13350
13351
}
13351
13352
const targetInfo = getIndexInfoOfType(target, kind);
13352
- if (!targetInfo || targetInfo.type.flags & TypeFlags.AnyOrUnknown && !sourceIsPrimitive) {
13353
+ if (!targetInfo || targetInfo.type.flags & TypeFlags.Any && !sourceIsPrimitive) {
13353
13354
// Index signature of type any permits assignment from everything but primitives
13354
13355
return Ternary.True;
13355
13356
}
@@ -14500,7 +14501,7 @@ namespace ts {
14500
14501
const templateType = getTemplateTypeFromMappedType(target);
14501
14502
const inference = createInferenceInfo(typeParameter);
14502
14503
inferTypes([inference], sourceType, templateType);
14503
- return getTypeFromInference(inference) || emptyObjectType ;
14504
+ return getTypeFromInference(inference) || unknownType ;
14504
14505
}
14505
14506
14506
14507
function* getUnmatchedProperties(source: Type, target: Type, requireOptionalProperties: boolean, matchDiscriminantProperties: boolean) {
@@ -15099,7 +15100,7 @@ namespace ts {
15099
15100
}
15100
15101
15101
15102
function getDefaultTypeArgumentType(isInJavaScriptFile: boolean): Type {
15102
- return isInJavaScriptFile ? anyType : emptyObjectType ;
15103
+ return isInJavaScriptFile ? anyType : unknownType ;
15103
15104
}
15104
15105
15105
15106
function getInferredTypes(context: InferenceContext): Type[] {
@@ -15443,7 +15444,7 @@ namespace ts {
15443
15444
return strictNullChecks ? TypeFacts.ObjectStrictFacts : TypeFacts.ObjectFacts;
15444
15445
}
15445
15446
if (flags & TypeFlags.Instantiable) {
15446
- return getTypeFacts(getBaseConstraintOfType(type) || emptyObjectType );
15447
+ return getTypeFacts(getBaseConstraintOfType(type) || unknownType );
15447
15448
}
15448
15449
if (flags & TypeFlags.UnionOrIntersection) {
15449
15450
return getTypeFactsOfTypes((<UnionOrIntersectionType>type).types);
@@ -16754,7 +16755,7 @@ namespace ts {
16754
16755
}
16755
16756
16756
16757
function typeHasNullableConstraint(type: Type) {
16757
- return type.flags & TypeFlags.InstantiableNonPrimitive && maybeTypeOfKind(getBaseConstraintOfType(type) || emptyObjectType , TypeFlags.Nullable);
16758
+ return type.flags & TypeFlags.InstantiableNonPrimitive && maybeTypeOfKind(getBaseConstraintOfType(type) || unknownType , TypeFlags.Nullable);
16758
16759
}
16759
16760
16760
16761
function getConstraintForLocation(type: Type, node: Node): Type;
@@ -18204,7 +18205,7 @@ namespace ts {
18204
18205
}
18205
18206
18206
18207
function getJsxPropsTypeFromCallSignature(sig: Signature, context: JsxOpeningLikeElement) {
18207
- let propsType = getTypeOfFirstParameterOfSignatureWithFallback(sig, emptyObjectType );
18208
+ let propsType = getTypeOfFirstParameterOfSignatureWithFallback(sig, unknownType );
18208
18209
propsType = getJsxManagedAttributesFromLocatedAttributes(context, getJsxNamespaceAt(context), propsType);
18209
18210
const intrinsicAttribs = getJsxType(JsxNames.IntrinsicAttributes, context);
18210
18211
if (intrinsicAttribs !== errorType) {
@@ -18278,7 +18279,7 @@ namespace ts {
18278
18279
const forcedLookupLocation = getJsxElementPropertiesName(ns);
18279
18280
let attributesType = forcedLookupLocation === undefined
18280
18281
// If there is no type ElementAttributesProperty, return the type of the first parameter of the signature, which should be the props type
18281
- ? getTypeOfFirstParameterOfSignatureWithFallback(sig, emptyObjectType )
18282
+ ? getTypeOfFirstParameterOfSignatureWithFallback(sig, unknownType )
18282
18283
: forcedLookupLocation === ""
18283
18284
// If there is no e.g. 'props' member in ElementAttributesProperty, use the element class type instead
18284
18285
? getReturnTypeOfSignature(sig)
@@ -18290,7 +18291,7 @@ namespace ts {
18290
18291
if (!!forcedLookupLocation && !!length(context.attributes.properties)) {
18291
18292
error(context, Diagnostics.JSX_element_class_does_not_support_attributes_because_it_does_not_have_a_0_property, unescapeLeadingUnderscores(forcedLookupLocation));
18292
18293
}
18293
- return emptyObjectType ;
18294
+ return unknownType ;
18294
18295
}
18295
18296
18296
18297
attributesType = getJsxManagedAttributesFromLocatedAttributes(context, ns, attributesType);
@@ -19501,7 +19502,7 @@ namespace ts {
19501
19502
undefinedDiagnostic?: DiagnosticMessage,
19502
19503
nullOrUndefinedDiagnostic?: DiagnosticMessage
19503
19504
): Type {
19504
- if (type.flags & TypeFlags.Unknown) {
19505
+ if (strictNullChecks && type.flags & TypeFlags.Unknown) {
19505
19506
error(node, Diagnostics.Object_is_of_type_unknown);
19506
19507
return errorType;
19507
19508
}
@@ -22000,7 +22001,7 @@ namespace ts {
22000
22001
const decl = parameter.valueDeclaration as ParameterDeclaration;
22001
22002
if (decl.name.kind !== SyntaxKind.Identifier) {
22002
22003
// if inference didn't come up with anything but {}, fall back to the binding pattern if present.
22003
- if (links.type === emptyObjectType ) {
22004
+ if (links.type === unknownType ) {
22004
22005
links.type = getTypeFromBindingPattern(decl.name);
22005
22006
}
22006
22007
assignBindingElementTypes(decl.name);
@@ -22013,28 +22014,28 @@ namespace ts {
22013
22014
const globalPromiseType = getGlobalPromiseType(/*reportErrors*/ true);
22014
22015
if (globalPromiseType !== emptyGenericType) {
22015
22016
// if the promised type is itself a promise, get the underlying type; otherwise, fallback to the promised type
22016
- promisedType = getAwaitedType(promisedType) || emptyObjectType ;
22017
+ promisedType = getAwaitedType(promisedType) || unknownType ;
22017
22018
return createTypeReference(globalPromiseType, [promisedType]);
22018
22019
}
22019
22020
22020
- return emptyObjectType ;
22021
+ return unknownType ;
22021
22022
}
22022
22023
22023
22024
function createPromiseLikeType(promisedType: Type): Type {
22024
22025
// creates a `PromiseLike<T>` type where `T` is the promisedType argument
22025
22026
const globalPromiseLikeType = getGlobalPromiseLikeType(/*reportErrors*/ true);
22026
22027
if (globalPromiseLikeType !== emptyGenericType) {
22027
22028
// if the promised type is itself a promise, get the underlying type; otherwise, fallback to the promised type
22028
- promisedType = getAwaitedType(promisedType) || emptyObjectType ;
22029
+ promisedType = getAwaitedType(promisedType) || unknownType ;
22029
22030
return createTypeReference(globalPromiseLikeType, [promisedType]);
22030
22031
}
22031
22032
22032
- return emptyObjectType ;
22033
+ return unknownType ;
22033
22034
}
22034
22035
22035
22036
function createPromiseReturnType(func: FunctionLikeDeclaration | ImportCall, promisedType: Type) {
22036
22037
const promiseType = createPromiseType(promisedType);
22037
- if (promiseType === emptyObjectType ) {
22038
+ if (promiseType === unknownType ) {
22038
22039
error(func, isImportCall(func) ?
22039
22040
Diagnostics.A_dynamic_import_call_returns_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option :
22040
22041
Diagnostics.An_async_function_or_method_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option);
@@ -23467,7 +23468,7 @@ namespace ts {
23467
23468
// If the contextual type is a type variable constrained to a primitive type, consider
23468
23469
// this a literal context for literals of that primitive type. For example, given a
23469
23470
// type parameter 'T extends string', infer string literal types for T.
23470
- const constraint = getBaseConstraintOfType(contextualType) || emptyObjectType ;
23471
+ const constraint = getBaseConstraintOfType(contextualType) || unknownType ;
23471
23472
return maybeTypeOfKind(constraint, TypeFlags.String) && maybeTypeOfKind(candidateType, TypeFlags.StringLiteral) ||
23472
23473
maybeTypeOfKind(constraint, TypeFlags.Number) && maybeTypeOfKind(candidateType, TypeFlags.NumberLiteral) ||
23473
23474
maybeTypeOfKind(constraint, TypeFlags.BigInt) && maybeTypeOfKind(candidateType, TypeFlags.BigIntLiteral) ||
0 commit comments