From 4761ba62855c605f46f747afefc675a4558ed965 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 7 Dec 2021 00:41:46 +0200 Subject: [PATCH] fix(46998): Hover on as const shows type const = /*unresolved*/ any (#47000) --- src/services/symbolDisplay.ts | 2 +- .../quickInfoForConstAssertions.baseline | 258 ++++++++++++++++++ .../fourslash/quickInfoForConstAssertions.ts | 8 + 3 files changed, 267 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/quickInfoForConstAssertions.baseline create mode 100644 tests/cases/fourslash/quickInfoForConstAssertions.ts diff --git a/src/services/symbolDisplay.ts b/src/services/symbolDisplay.ts index 83508dbf936..f1447b30cd9 100644 --- a/src/services/symbolDisplay.ts +++ b/src/services/symbolDisplay.ts @@ -330,7 +330,7 @@ namespace ts.SymbolDisplay { displayParts.push(spacePart()); displayParts.push(operatorPart(SyntaxKind.EqualsToken)); displayParts.push(spacePart()); - addRange(displayParts, typeToDisplayParts(typeChecker, typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration, TypeFormatFlags.InTypeAlias)); + addRange(displayParts, typeToDisplayParts(typeChecker, isConstTypeReference(location.parent) ? typeChecker.getTypeAtLocation(location.parent) : typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration, TypeFormatFlags.InTypeAlias)); } if (symbolFlags & SymbolFlags.Enum) { prefixNextMeaning(); diff --git a/tests/baselines/reference/quickInfoForConstAssertions.baseline b/tests/baselines/reference/quickInfoForConstAssertions.baseline new file mode 100644 index 00000000000..9fccd0dbe44 --- /dev/null +++ b/tests/baselines/reference/quickInfoForConstAssertions.baseline @@ -0,0 +1,258 @@ +[ + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoForConstAssertions.ts", + "position": 22, + "name": "1" + }, + "quickInfo": { + "kind": "type", + "kindModifiers": "", + "textSpan": { + "start": 22, + "length": 5 + }, + "displayParts": [ + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "{", + "kind": "punctuation" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "readonly", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "a", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "1", + "kind": "stringLiteral" + }, + { + "text": ";", + "kind": "punctuation" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "}", + "kind": "punctuation" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoForConstAssertions.ts", + "position": 44, + "name": "2" + }, + "quickInfo": { + "kind": "type", + "kindModifiers": "", + "textSpan": { + "start": 44, + "length": 5 + }, + "displayParts": [ + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "1", + "kind": "stringLiteral" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoForConstAssertions.ts", + "position": 68, + "name": "3" + }, + "quickInfo": { + "kind": "type", + "kindModifiers": "", + "textSpan": { + "start": 68, + "length": 5 + }, + "displayParts": [ + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"c\"", + "kind": "stringLiteral" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoForConstAssertions.ts", + "position": 95, + "name": "4" + }, + "quickInfo": { + "kind": "type", + "kindModifiers": "", + "textSpan": { + "start": 95, + "length": 5 + }, + "displayParts": [ + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "readonly", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "[", + "kind": "punctuation" + }, + { + "text": "1", + "kind": "stringLiteral" + }, + { + "text": ",", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "2", + "kind": "stringLiteral" + }, + { + "text": "]", + "kind": "punctuation" + } + ], + "documentation": [] + } + } +] \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoForConstAssertions.ts b/tests/cases/fourslash/quickInfoForConstAssertions.ts new file mode 100644 index 00000000000..d87d7c7c1e5 --- /dev/null +++ b/tests/cases/fourslash/quickInfoForConstAssertions.ts @@ -0,0 +1,8 @@ +/// + +////const a = { a: 1 } as /*1*/const; +////const b = 1 as /*2*/const; +////const c = "c" as /*3*/const; +////const d = [1, 2] as /*4*/const; + +verify.baselineQuickInfo();