From ef0422b40fd0882723adf1aa32c7da122ffa526a Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Wed, 19 Jul 2023 02:42:04 +0300 Subject: [PATCH] fix(54872): Have createUnionOfSignaturesForOverloadFailure() combine @deprecated tags properly (#54945) --- src/compiler/checker.ts | 3 ++- src/compiler/types.ts | 3 ++- .../fourslash/jsdocDeprecated_suggestion22.ts | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/jsdocDeprecated_suggestion22.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f1324425367..2062f2412c1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -33488,7 +33488,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { parameters.push(createCombinedSymbolFromTypes(symbols, mapDefined(candidates, candidate => tryGetTypeAtPosition(candidate, i)))); } const restParameterSymbols = mapDefined(candidates, c => signatureHasRestParameter(c) ? last(c.parameters) : undefined); - let flags = SignatureFlags.None; + let flags = SignatureFlags.IsSignatureCandidateForOverloadFailure; if (restParameterSymbols.length !== 0) { const type = createArrayType(getUnionType(mapDefined(candidates, tryGetRestTypeOfSignature), UnionReduction.Subtype)); parameters.push(createCombinedSymbolForOverloadFailure(restParameterSymbols, type)); @@ -34386,6 +34386,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function checkDeprecatedSignature(signature: Signature, node: CallLikeExpression) { + if (signature.flags & SignatureFlags.IsSignatureCandidateForOverloadFailure) return; if (signature.declaration && signature.declaration.flags & NodeFlags.Deprecated) { const suggestionNode = getDeprecatedSuggestionNode(node); const name = tryGetPropertyAccessOrIdentifierToString(getInvokedExpression(node)); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 63ca3980ca6..82711dbd763 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -6724,11 +6724,12 @@ export const enum SignatureFlags { IsOuterCallChain = 1 << 4, // Indicates signature comes from a CallChain that is the outermost chain of an optional expression IsUntypedSignatureInJSFile = 1 << 5, // Indicates signature is from a js file and has no types IsNonInferrable = 1 << 6, // Indicates signature comes from a non-inferrable type + IsSignatureCandidateForOverloadFailure = 1 << 7, // We do not propagate `IsInnerCallChain` or `IsOuterCallChain` to instantiated signatures, as that would result in us // attempting to add `| undefined` on each recursive call to `getReturnTypeOfSignature` when // instantiating the return type. - PropagatingFlags = HasRestParameter | HasLiteralTypes | Abstract | IsUntypedSignatureInJSFile, + PropagatingFlags = HasRestParameter | HasLiteralTypes | Abstract | IsUntypedSignatureInJSFile | IsSignatureCandidateForOverloadFailure, CallChainFlags = IsInnerCallChain | IsOuterCallChain, } diff --git a/tests/cases/fourslash/jsdocDeprecated_suggestion22.ts b/tests/cases/fourslash/jsdocDeprecated_suggestion22.ts new file mode 100644 index 00000000000..63b7543eb15 --- /dev/null +++ b/tests/cases/fourslash/jsdocDeprecated_suggestion22.ts @@ -0,0 +1,14 @@ +/// + +// @filename: /a.ts +////const foo: { +//// /** +//// * @deprecated +//// */ +//// (a: string, b: string): string; +//// (a: string, b: number): string; +////} = (a: string, b: string | number) => a + b; +//// +////[|foo|](1, 1); + +verify.getSuggestionDiagnostics([]);