mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Don't issue implicit any when obtaining the implied type for a binding pattern (#60083)
Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
This commit is contained in:
co-authored by
Jake Bailey
parent
35902c2e77
commit
ca18009b8b
@@ -11633,7 +11633,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
// contextual type or, if the element itself is a binding pattern, with the type implied by that binding
|
||||
// pattern.
|
||||
const contextualType = isBindingPattern(element.name) ? getTypeFromBindingPattern(element.name, /*includePatternInType*/ true, /*reportErrors*/ false) : unknownType;
|
||||
return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, CheckMode.Normal, contextualType)));
|
||||
return addOptionality(getWidenedLiteralTypeForInitializer(element, checkDeclarationInitializer(element, CheckMode.Normal, contextualType)));
|
||||
}
|
||||
if (isBindingPattern(element.name)) {
|
||||
return getTypeFromBindingPattern(element.name, includePatternInType, reportErrors);
|
||||
@@ -40523,7 +40523,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
}
|
||||
|
||||
function widenTypeInferredFromInitializer(declaration: HasExpressionInitializer, type: Type) {
|
||||
const widened = getCombinedNodeFlagsCached(declaration) & NodeFlags.Constant || isDeclarationReadonly(declaration) ? type : getWidenedLiteralType(type);
|
||||
const widened = getWidenedLiteralTypeForInitializer(declaration, type);
|
||||
if (isInJSFile(declaration)) {
|
||||
if (isEmptyLiteralType(widened)) {
|
||||
reportImplicitAny(declaration, anyType);
|
||||
@@ -40537,6 +40537,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
return widened;
|
||||
}
|
||||
|
||||
function getWidenedLiteralTypeForInitializer(declaration: HasExpressionInitializer, type: Type) {
|
||||
return getCombinedNodeFlagsCached(declaration) & NodeFlags.Constant || isDeclarationReadonly(declaration) ? type : getWidenedLiteralType(type);
|
||||
}
|
||||
|
||||
function isLiteralOfContextualType(candidateType: Type, contextualType: Type | undefined): boolean {
|
||||
if (contextualType) {
|
||||
if (contextualType.flags & TypeFlags.UnionOrIntersection) {
|
||||
|
||||
Reference in New Issue
Block a user