mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-15 12:53:27 -05:00
Unwrap parens when checking for JSDocFunctionType in conditional expression (#46962)
This commit is contained in:
@@ -4539,10 +4539,16 @@ namespace ts {
|
||||
// - "(x,y)" is a comma expression parsed as a signature with two parameters.
|
||||
// - "a ? (b): c" will have "(b):" parsed as a signature with a return type annotation.
|
||||
// - "a ? (b): function() {}" will too, since function() is a valid JSDoc function type.
|
||||
// - "a ? (b): (function() {})" as well, but inside of a parenthesized type.
|
||||
// - "a ? (b): (function() {})" as well, but inside of a parenthesized type with an arbitrary amount of nesting.
|
||||
//
|
||||
// So we need just a bit of lookahead to ensure that it can only be a signature.
|
||||
const hasJSDocFunctionType = type && (isJSDocFunctionType(type) || isParenthesizedTypeNode(type) && isJSDocFunctionType(type.type));
|
||||
|
||||
let unwrappedType = type;
|
||||
while (unwrappedType?.kind === SyntaxKind.ParenthesizedType) {
|
||||
unwrappedType = (unwrappedType as ParenthesizedTypeNode).type; // Skip parens if need be
|
||||
}
|
||||
|
||||
const hasJSDocFunctionType = unwrappedType && isJSDocFunctionType(unwrappedType);
|
||||
if (!allowAmbiguity && token() !== SyntaxKind.EqualsGreaterThanToken && (hasJSDocFunctionType || token() !== SyntaxKind.OpenBraceToken)) {
|
||||
// Returning undefined here will cause our caller to rewind to where we started from.
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user