Skip to content

Commit 4761ba6

Browse files
authored
fix(46998): Hover on as const shows type const = /*unresolved*/ any (microsoft#47000)
1 parent 1fe9bfd commit 4761ba6

File tree

3 files changed

+267
-1
lines changed

3 files changed

+267
-1
lines changed

src/services/symbolDisplay.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ namespace ts.SymbolDisplay {
330330
displayParts.push(spacePart());
331331
displayParts.push(operatorPart(SyntaxKind.EqualsToken));
332332
displayParts.push(spacePart());
333-
addRange(displayParts, typeToDisplayParts(typeChecker, typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration, TypeFormatFlags.InTypeAlias));
333+
addRange(displayParts, typeToDisplayParts(typeChecker, isConstTypeReference(location.parent) ? typeChecker.getTypeAtLocation(location.parent) : typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration, TypeFormatFlags.InTypeAlias));
334334
}
335335
if (symbolFlags & SymbolFlags.Enum) {
336336
prefixNextMeaning();
Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
[
2+
{
3+
"marker": {
4+
"fileName": "/tests/cases/fourslash/quickInfoForConstAssertions.ts",
5+
"position": 22,
6+
"name": "1"
7+
},
8+
"quickInfo": {
9+
"kind": "type",
10+
"kindModifiers": "",
11+
"textSpan": {
12+
"start": 22,
13+
"length": 5
14+
},
15+
"displayParts": [
16+
{
17+
"text": "type",
18+
"kind": "keyword"
19+
},
20+
{
21+
"text": " ",
22+
"kind": "space"
23+
},
24+
{
25+
"text": "const",
26+
"kind": "aliasName"
27+
},
28+
{
29+
"text": " ",
30+
"kind": "space"
31+
},
32+
{
33+
"text": "=",
34+
"kind": "operator"
35+
},
36+
{
37+
"text": " ",
38+
"kind": "space"
39+
},
40+
{
41+
"text": "{",
42+
"kind": "punctuation"
43+
},
44+
{
45+
"text": "\n",
46+
"kind": "lineBreak"
47+
},
48+
{
49+
"text": " ",
50+
"kind": "space"
51+
},
52+
{
53+
"text": "readonly",
54+
"kind": "keyword"
55+
},
56+
{
57+
"text": " ",
58+
"kind": "space"
59+
},
60+
{
61+
"text": "a",
62+
"kind": "propertyName"
63+
},
64+
{
65+
"text": ":",
66+
"kind": "punctuation"
67+
},
68+
{
69+
"text": " ",
70+
"kind": "space"
71+
},
72+
{
73+
"text": "1",
74+
"kind": "stringLiteral"
75+
},
76+
{
77+
"text": ";",
78+
"kind": "punctuation"
79+
},
80+
{
81+
"text": "\n",
82+
"kind": "lineBreak"
83+
},
84+
{
85+
"text": "}",
86+
"kind": "punctuation"
87+
}
88+
],
89+
"documentation": []
90+
}
91+
},
92+
{
93+
"marker": {
94+
"fileName": "/tests/cases/fourslash/quickInfoForConstAssertions.ts",
95+
"position": 44,
96+
"name": "2"
97+
},
98+
"quickInfo": {
99+
"kind": "type",
100+
"kindModifiers": "",
101+
"textSpan": {
102+
"start": 44,
103+
"length": 5
104+
},
105+
"displayParts": [
106+
{
107+
"text": "type",
108+
"kind": "keyword"
109+
},
110+
{
111+
"text": " ",
112+
"kind": "space"
113+
},
114+
{
115+
"text": "const",
116+
"kind": "aliasName"
117+
},
118+
{
119+
"text": " ",
120+
"kind": "space"
121+
},
122+
{
123+
"text": "=",
124+
"kind": "operator"
125+
},
126+
{
127+
"text": " ",
128+
"kind": "space"
129+
},
130+
{
131+
"text": "1",
132+
"kind": "stringLiteral"
133+
}
134+
],
135+
"documentation": []
136+
}
137+
},
138+
{
139+
"marker": {
140+
"fileName": "/tests/cases/fourslash/quickInfoForConstAssertions.ts",
141+
"position": 68,
142+
"name": "3"
143+
},
144+
"quickInfo": {
145+
"kind": "type",
146+
"kindModifiers": "",
147+
"textSpan": {
148+
"start": 68,
149+
"length": 5
150+
},
151+
"displayParts": [
152+
{
153+
"text": "type",
154+
"kind": "keyword"
155+
},
156+
{
157+
"text": " ",
158+
"kind": "space"
159+
},
160+
{
161+
"text": "const",
162+
"kind": "aliasName"
163+
},
164+
{
165+
"text": " ",
166+
"kind": "space"
167+
},
168+
{
169+
"text": "=",
170+
"kind": "operator"
171+
},
172+
{
173+
"text": " ",
174+
"kind": "space"
175+
},
176+
{
177+
"text": "\"c\"",
178+
"kind": "stringLiteral"
179+
}
180+
],
181+
"documentation": []
182+
}
183+
},
184+
{
185+
"marker": {
186+
"fileName": "/tests/cases/fourslash/quickInfoForConstAssertions.ts",
187+
"position": 95,
188+
"name": "4"
189+
},
190+
"quickInfo": {
191+
"kind": "type",
192+
"kindModifiers": "",
193+
"textSpan": {
194+
"start": 95,
195+
"length": 5
196+
},
197+
"displayParts": [
198+
{
199+
"text": "type",
200+
"kind": "keyword"
201+
},
202+
{
203+
"text": " ",
204+
"kind": "space"
205+
},
206+
{
207+
"text": "const",
208+
"kind": "aliasName"
209+
},
210+
{
211+
"text": " ",
212+
"kind": "space"
213+
},
214+
{
215+
"text": "=",
216+
"kind": "operator"
217+
},
218+
{
219+
"text": " ",
220+
"kind": "space"
221+
},
222+
{
223+
"text": "readonly",
224+
"kind": "keyword"
225+
},
226+
{
227+
"text": " ",
228+
"kind": "space"
229+
},
230+
{
231+
"text": "[",
232+
"kind": "punctuation"
233+
},
234+
{
235+
"text": "1",
236+
"kind": "stringLiteral"
237+
},
238+
{
239+
"text": ",",
240+
"kind": "punctuation"
241+
},
242+
{
243+
"text": " ",
244+
"kind": "space"
245+
},
246+
{
247+
"text": "2",
248+
"kind": "stringLiteral"
249+
},
250+
{
251+
"text": "]",
252+
"kind": "punctuation"
253+
}
254+
],
255+
"documentation": []
256+
}
257+
}
258+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////const a = { a: 1 } as /*1*/const;
4+
////const b = 1 as /*2*/const;
5+
////const c = "c" as /*3*/const;
6+
////const d = [1, 2] as /*4*/const;
7+
8+
verify.baselineQuickInfo();

0 commit comments

Comments
 (0)