mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 15:45:27 -05:00
fix(43030): fix instantiated null/undefined type from JS initializer (#43933)
This commit is contained in:
@@ -20025,9 +20025,13 @@ namespace ts {
|
||||
return (type as TypeReference).cachedEquivalentBaseType = instantiatedBase;
|
||||
}
|
||||
|
||||
function isEmptyLiteralType(type: Type): boolean {
|
||||
return strictNullChecks ? type === implicitNeverType : type === undefinedWideningType;
|
||||
}
|
||||
|
||||
function isEmptyArrayLiteralType(type: Type): boolean {
|
||||
const elementType = getElementTypeOfArrayType(type);
|
||||
return strictNullChecks ? elementType === implicitNeverType : elementType === undefinedWideningType;
|
||||
return !!elementType && isEmptyLiteralType(elementType);
|
||||
}
|
||||
|
||||
function isTupleLikeType(type: Type): boolean {
|
||||
@@ -32355,7 +32359,7 @@ namespace ts {
|
||||
function widenTypeInferredFromInitializer(declaration: HasExpressionInitializer, type: Type) {
|
||||
const widened = getCombinedNodeFlags(declaration) & NodeFlags.Const || isDeclarationReadonly(declaration) ? type : getWidenedLiteralType(type);
|
||||
if (isInJSFile(declaration)) {
|
||||
if (widened.flags & TypeFlags.Nullable) {
|
||||
if (isEmptyLiteralType(widened)) {
|
||||
reportImplicitAny(declaration, anyType);
|
||||
return anyType;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user