diff --git a/src/services/inlayHints.ts b/src/services/inlayHints.ts index f36b6e7d087..110e9718405 100644 --- a/src/services/inlayHints.ts +++ b/src/services/inlayHints.ts @@ -279,7 +279,7 @@ namespace ts.InlayHints { continue; } - addTypeHints(typeDisplayString, param.name.end); + addTypeHints(typeDisplayString, param.questionToken ? param.questionToken.end : param.name.end); } } diff --git a/tests/cases/fourslash/inlayHintsShouldWork66.ts b/tests/cases/fourslash/inlayHintsShouldWork66.ts new file mode 100644 index 00000000000..618348a6911 --- /dev/null +++ b/tests/cases/fourslash/inlayHintsShouldWork66.ts @@ -0,0 +1,23 @@ +/// + +////interface IFoo { +//// bar(x?: boolean): void; +////} +//// +////const a: IFoo = { +//// bar: function (x?/**/): void { +//// throw new Error("Function not implemented."); +//// } +////} + +const [marker] = test.markers(); +verify.getInlayHints([ + { + text: ': boolean', + position: marker.position, + kind: ts.InlayHintKind.Type, + whitespaceBefore: true + }, +], undefined, { + includeInlayFunctionParameterTypeHints: true +});