mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
Delay pulling on signature contextual type until absolutely needed (#37851)
This commit is contained in:
@@ -55,7 +55,9 @@ namespace ts {
|
||||
|
||||
const enum WideningKind {
|
||||
Normal,
|
||||
GeneratorYield
|
||||
FunctionReturn,
|
||||
GeneratorNext,
|
||||
GeneratorYield,
|
||||
}
|
||||
|
||||
const enum TypeFacts {
|
||||
@@ -18092,7 +18094,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function reportErrorsFromWidening(declaration: Declaration, type: Type, wideningKind?: WideningKind) {
|
||||
if (produceDiagnostics && noImplicitAny && getObjectFlags(type) & ObjectFlags.ContainsWideningType) {
|
||||
if (produceDiagnostics && noImplicitAny && getObjectFlags(type) & ObjectFlags.ContainsWideningType && (!wideningKind || !getContextualSignatureForFunctionLikeDeclaration(declaration as FunctionLikeDeclaration))) {
|
||||
// Report implicit any error within type if possible, otherwise report error on declaration
|
||||
if (!reportWideningErrorsInType(type)) {
|
||||
reportImplicitAny(declaration, type, wideningKind);
|
||||
@@ -27047,15 +27049,13 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (returnType || yieldType || nextType) {
|
||||
const contextualSignature = getContextualSignatureForFunctionLikeDeclaration(func);
|
||||
if (!contextualSignature) {
|
||||
if (yieldType) reportErrorsFromWidening(func, yieldType, WideningKind.GeneratorYield);
|
||||
if (returnType) reportErrorsFromWidening(func, returnType);
|
||||
if (nextType) reportErrorsFromWidening(func, nextType);
|
||||
}
|
||||
if (yieldType) reportErrorsFromWidening(func, yieldType, WideningKind.GeneratorYield);
|
||||
if (returnType) reportErrorsFromWidening(func, returnType, WideningKind.FunctionReturn);
|
||||
if (nextType) reportErrorsFromWidening(func, nextType, WideningKind.GeneratorNext);
|
||||
if (returnType && isUnitType(returnType) ||
|
||||
yieldType && isUnitType(yieldType) ||
|
||||
nextType && isUnitType(nextType)) {
|
||||
const contextualSignature = getContextualSignatureForFunctionLikeDeclaration(func);
|
||||
const contextualType = !contextualSignature ? undefined :
|
||||
contextualSignature === getSignatureFromDeclaration(func) ? isGenerator ? undefined : returnType :
|
||||
instantiateContextualType(getReturnTypeOfSignature(contextualSignature), func);
|
||||
|
||||
Reference in New Issue
Block a user