Skip to content

Commit

Permalink
fix(57445): No inlay hints for property declaration types inferred fr…
Browse files Browse the repository at this point in the history
…om constructor (#57494)

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
  • Loading branch information
a-tarasyuk and sandersn committed Mar 12, 2024
1 parent 47a800f commit 884d649
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/services/inlayHints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ import {
tokenToString,
TupleTypeReference,
Type,
TypeFlags,
unescapeLeadingUnderscores,
UserPreferences,
usingSingleLineStringWriter,
Expand Down Expand Up @@ -260,7 +261,10 @@ export function provideInlayHints(context: InlayHintsContext): InlayHint[] {
}

function visitVariableLikeDeclaration(decl: VariableDeclaration | PropertyDeclaration) {
if (!decl.initializer || isBindingPattern(decl.name) || isVariableDeclaration(decl) && !isHintableDeclaration(decl)) {
if (
decl.initializer === undefined && !(isPropertyDeclaration(decl) && !(checker.getTypeAtLocation(decl).flags & TypeFlags.Any)) ||
isBindingPattern(decl.name) || (isVariableDeclaration(decl) && !isHintableDeclaration(decl))
) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@
"position": 15,
"kind": "Type",
"whitespaceBefore": true
}

d;
^
{
"text": ": number | null",
"position": 50,
"kind": "Type",
"whitespaceBefore": true
}
9 changes: 9 additions & 0 deletions tests/cases/fourslash/inlayHintsPropertyDeclarations.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
/// <reference path="fourslash.ts" />

// @strict: true
//// class C {
//// a = 1
//// b: number = 2
//// c;
//// d;
////
//// constructor(value: number) {
//// this.d = value;
//// if (value <= 0) {
//// this.d = null;
//// }
//// }
//// }

verify.baselineInlayHints(undefined, {
Expand Down

0 comments on commit 884d649

Please sign in to comment.