Fixed crash on ComputedPropertyName when computing interactive inlay hints (#61857)

This commit is contained in:
Mateusz Burzyński 2025-06-30 19:28:27 +02:00 committed by GitHub
parent 36f7fbaded
commit 8665f920c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 69 additions and 0 deletions

View File

@ -42,6 +42,7 @@ import {
isBindingPattern,
isCallExpression,
isCallSignatureDeclaration,
isComputedPropertyName,
isConditionalTypeNode,
isConstructorTypeNode,
isConstructSignatureDeclaration,
@ -886,6 +887,12 @@ export function provideInlayHints(context: InlayHintsContext): InlayHint[] {
Debug.assertNode(node, isThisTypeNode);
parts.push({ text: "this" });
break;
case SyntaxKind.ComputedPropertyName:
Debug.assertNode(node, isComputedPropertyName);
parts.push({ text: "[" });
visitForDisplayParts(node.expression);
parts.push({ text: "]" });
break;
default:
Debug.failBadSyntaxKind(node);
}

View File

@ -0,0 +1,46 @@
// === Inlay Hints ===
test((state) => {});
^
{
"text": "",
"displayParts": [
{
"text": ": "
},
{
"text": "{"
},
{
"text": " "
},
{
"text": "["
},
{
"text": "STATE_SIGNAL",
"span": {
"start": 14,
"length": 12
},
"file": "/tests/cases/fourslash/inlayHintsFunctionParameterTypes5.ts"
},
{
"text": "]"
},
{
"text": ": "
},
{
"text": "unknown"
},
{
"text": " "
},
{
"text": "}"
}
],
"position": 143,
"kind": "Type",
"whitespaceBefore": true
}

View File

@ -0,0 +1,16 @@
/// <reference path="fourslash.ts" />
// https://github.com/microsoft/TypeScript/issues/61845
//// declare const STATE_SIGNAL: unique symbol;
////
//// declare function test(
//// cb: (state: { [STATE_SIGNAL]: unknown }) => void,
//// ): unknown;
////
//// test((state) => {});
verify.baselineInlayHints(undefined, {
includeInlayFunctionParameterTypeHints: true,
interactiveInlayHints: true,
});