Skip to content

Commit 884d649

Browse files
a-tarasyuksandersn
andauthored
fix(57445): No inlay hints for property declaration types inferred from constructor (#57494)
Co-authored-by: Nathan Shively-Sanders <[email protected]>
1 parent 47a800f commit 884d649

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/services/inlayHints.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ import {
118118
tokenToString,
119119
TupleTypeReference,
120120
Type,
121+
TypeFlags,
121122
unescapeLeadingUnderscores,
122123
UserPreferences,
123124
usingSingleLineStringWriter,
@@ -260,7 +261,10 @@ export function provideInlayHints(context: InlayHintsContext): InlayHint[] {
260261
}
261262

262263
function visitVariableLikeDeclaration(decl: VariableDeclaration | PropertyDeclaration) {
263-
if (!decl.initializer || isBindingPattern(decl.name) || isVariableDeclaration(decl) && !isHintableDeclaration(decl)) {
264+
if (
265+
decl.initializer === undefined && !(isPropertyDeclaration(decl) && !(checker.getTypeAtLocation(decl).flags & TypeFlags.Any)) ||
266+
isBindingPattern(decl.name) || (isVariableDeclaration(decl) && !isHintableDeclaration(decl))
267+
) {
264268
return;
265269
}
266270

tests/baselines/reference/inlayHintsPropertyDeclarations.baseline

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,13 @@
66
"position": 15,
77
"kind": "Type",
88
"whitespaceBefore": true
9+
}
10+
11+
d;
12+
^
13+
{
14+
"text": ": number | null",
15+
"position": 50,
16+
"kind": "Type",
17+
"whitespaceBefore": true
918
}

tests/cases/fourslash/inlayHintsPropertyDeclarations.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
/// <reference path="fourslash.ts" />
22

3+
// @strict: true
34
//// class C {
45
//// a = 1
56
//// b: number = 2
67
//// c;
8+
//// d;
9+
////
10+
//// constructor(value: number) {
11+
//// this.d = value;
12+
//// if (value <= 0) {
13+
//// this.d = null;
14+
//// }
15+
//// }
716
//// }
817

918
verify.baselineInlayHints(undefined, {

0 commit comments

Comments
 (0)