Skip to content

Commit 7cdc81e

Browse files
committed
feat(49385): forbid inlay hints for literal-initialized constants
1 parent 2f13eba commit 7cdc81e

File tree

6 files changed

+9
-36
lines changed

6 files changed

+9
-36
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ namespace ts {
655655
isArrayType,
656656
isTupleType,
657657
isArrayLikeType,
658+
isLiteralConstDeclaration,
658659
isTypeInvalidDueToUnionDiscriminant,
659660
getExactOptionalProperties,
660661
getAllPossiblePropertiesOfTypes,

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4401,6 +4401,7 @@ namespace ts {
44014401
/* @internal */ isArrayType(type: Type): boolean;
44024402
/* @internal */ isTupleType(type: Type): boolean;
44034403
/* @internal */ isArrayLikeType(type: Type): boolean;
4404+
/* @internal */ isLiteralConstDeclaration(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration): boolean;
44044405

44054406
/**
44064407
* True if `contextualType` should not be considered for completions because

src/services/inlayHints.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ namespace ts.InlayHints {
121121
}
122122

123123
function visitVariableLikeDeclaration(decl: VariableDeclaration | PropertyDeclaration) {
124-
if (!decl.initializer || isBindingPattern(decl.name)) {
124+
if (!decl.initializer || isBindingPattern(decl.name) || checker.isLiteralConstDeclaration(decl)) {
125125
return;
126126
}
127127

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

3-
//// const a/*a*/ = 123;
3+
////const a = "a";
4+
////const b = 1;
5+
////const c = true;
46

5-
const markers = test.markers();
6-
verify.getInlayHints([
7-
{
8-
text: ': 123',
9-
position: markers[0].position,
10-
kind: ts.InlayHintKind.Type,
11-
whitespaceBefore: true
12-
},
13-
], undefined, {
7+
verify.getInlayHints([], undefined, {
148
includeInlayVariableTypeHints: true
159
});

tests/cases/fourslash/inlayHintsShouldWork16.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
/// <reference path="fourslash.ts" />
22

3-
//// const a/*a*/ = "I'm very very very very very very very very very long";
3+
////const a = "I'm very very very very very very very very very long";
44

5-
const markers = test.markers();
6-
verify.getInlayHints([
7-
{
8-
text: `: "I'm very very very very ve...`,
9-
position: markers[0].position,
10-
kind: ts.InlayHintKind.Type,
11-
whitespaceBefore: true
12-
},
13-
], undefined, {
5+
verify.getInlayHints([], undefined, {
146
includeInlayVariableTypeHints: true
157
});

0 commit comments

Comments
 (0)