mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 12:32:08 -06:00
fix(56737): unique symbol quick info is different in JS than TS (#56743)
This commit is contained in:
parent
a50f67d347
commit
382de91763
@ -19107,6 +19107,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
}
|
||||
|
||||
function getESSymbolLikeTypeForNode(node: Node) {
|
||||
if (isInJSFile(node) && isJSDocTypeExpression(node)) {
|
||||
const host = getJSDocHost(node);
|
||||
if (host) {
|
||||
node = getSingleVariableOfVariableStatement(host) || host;
|
||||
}
|
||||
}
|
||||
if (isValidESSymbolDeclaration(node)) {
|
||||
const symbol = isCommonJsExportPropertyAssignment(node) ? getSymbolOfNode((node as BinaryExpression).left) : getSymbolOfNode(node);
|
||||
if (symbol) {
|
||||
|
||||
@ -0,0 +1,74 @@
|
||||
// === QuickInfo ===
|
||||
=== /tests/cases/fourslash/./a.js ===
|
||||
// /** @type {unique symbol} */
|
||||
// const foo = Symbol();
|
||||
// foo
|
||||
// ^^^
|
||||
// | ----------------------------------------------------------------------
|
||||
// | const foo: typeof foo
|
||||
// | @type {unique symbol}
|
||||
// | ----------------------------------------------------------------------
|
||||
|
||||
[
|
||||
{
|
||||
"marker": {
|
||||
"fileName": "/tests/cases/fourslash/./a.js",
|
||||
"position": 54,
|
||||
"name": ""
|
||||
},
|
||||
"item": {
|
||||
"kind": "const",
|
||||
"kindModifiers": "",
|
||||
"textSpan": {
|
||||
"start": 51,
|
||||
"length": 3
|
||||
},
|
||||
"displayParts": [
|
||||
{
|
||||
"text": "const",
|
||||
"kind": "keyword"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "foo",
|
||||
"kind": "localName"
|
||||
},
|
||||
{
|
||||
"text": ":",
|
||||
"kind": "punctuation"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "typeof",
|
||||
"kind": "keyword"
|
||||
},
|
||||
{
|
||||
"text": " ",
|
||||
"kind": "space"
|
||||
},
|
||||
{
|
||||
"text": "foo",
|
||||
"kind": "localName"
|
||||
}
|
||||
],
|
||||
"documentation": [],
|
||||
"tags": [
|
||||
{
|
||||
"name": "type",
|
||||
"text": [
|
||||
{
|
||||
"text": "{unique symbol}",
|
||||
"kind": "text"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
15
tests/baselines/reference/uniqueSymbolJs.errors.txt
Normal file
15
tests/baselines/reference/uniqueSymbolJs.errors.txt
Normal file
@ -0,0 +1,15 @@
|
||||
a.js(5,18): error TS1337: An index signature parameter type cannot be a literal type or generic type. Consider using a mapped object type instead.
|
||||
a.js(5,28): error TS1005: ';' expected.
|
||||
|
||||
|
||||
==== ./a.js (2 errors) ====
|
||||
/** @type {unique symbol} */
|
||||
const foo = Symbol();
|
||||
|
||||
/** @typedef {{ [foo]: boolean }} A */
|
||||
/** @typedef {{ [key: foo] boolean }} B */
|
||||
~~~
|
||||
!!! error TS1337: An index signature parameter type cannot be a literal type or generic type. Consider using a mapped object type instead.
|
||||
~~~~~~~
|
||||
!!! error TS1005: ';' expected.
|
||||
|
||||
11
tests/baselines/reference/uniqueSymbolJs.symbols
Normal file
11
tests/baselines/reference/uniqueSymbolJs.symbols
Normal file
@ -0,0 +1,11 @@
|
||||
//// [tests/cases/compiler/uniqueSymbolJs.ts] ////
|
||||
|
||||
=== ./a.js ===
|
||||
/** @type {unique symbol} */
|
||||
const foo = Symbol();
|
||||
>foo : Symbol(foo, Decl(a.js, 1, 5))
|
||||
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2019.symbol.d.ts, --, --))
|
||||
|
||||
/** @typedef {{ [foo]: boolean }} A */
|
||||
/** @typedef {{ [key: foo] boolean }} B */
|
||||
|
||||
12
tests/baselines/reference/uniqueSymbolJs.types
Normal file
12
tests/baselines/reference/uniqueSymbolJs.types
Normal file
@ -0,0 +1,12 @@
|
||||
//// [tests/cases/compiler/uniqueSymbolJs.ts] ////
|
||||
|
||||
=== ./a.js ===
|
||||
/** @type {unique symbol} */
|
||||
const foo = Symbol();
|
||||
>foo : unique symbol
|
||||
>Symbol() : unique symbol
|
||||
>Symbol : SymbolConstructor
|
||||
|
||||
/** @typedef {{ [foo]: boolean }} A */
|
||||
/** @typedef {{ [key: foo] boolean }} B */
|
||||
|
||||
@ -18,14 +18,14 @@ class C {
|
||||
* @readonly
|
||||
*/
|
||||
static readonlyStaticType;
|
||||
>readonlyStaticType : symbol
|
||||
>readonlyStaticType : unique symbol
|
||||
|
||||
/**
|
||||
* @type {unique symbol}
|
||||
* @readonly
|
||||
*/
|
||||
static readonlyStaticTypeAndCall = Symbol();
|
||||
>readonlyStaticTypeAndCall : symbol
|
||||
>readonlyStaticTypeAndCall : unique symbol
|
||||
>Symbol() : unique symbol
|
||||
>Symbol : SymbolConstructor
|
||||
|
||||
@ -50,7 +50,7 @@ class C {
|
||||
|
||||
/** @type {unique symbol} */
|
||||
const a = Symbol();
|
||||
>a : symbol
|
||||
>a : unique symbol
|
||||
>Symbol() : unique symbol
|
||||
>Symbol : SymbolConstructor
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ class C {
|
||||
* @readonly
|
||||
*/
|
||||
static readonlyType;
|
||||
>readonlyType : symbol
|
||||
>readonlyType : unique symbol
|
||||
|
||||
/**
|
||||
* @type {unique symbol}
|
||||
|
||||
11
tests/cases/compiler/uniqueSymbolJs.ts
Normal file
11
tests/cases/compiler/uniqueSymbolJs.ts
Normal file
@ -0,0 +1,11 @@
|
||||
// @target: esnext
|
||||
// @checkJs: true
|
||||
// @allowJs: true
|
||||
// @noEmit: true
|
||||
// @filename: ./a.js
|
||||
|
||||
/** @type {unique symbol} */
|
||||
const foo = Symbol();
|
||||
|
||||
/** @typedef {{ [foo]: boolean }} A */
|
||||
/** @typedef {{ [key: foo] boolean }} B */
|
||||
10
tests/cases/fourslash/quickInfoUniqueSymbolJsDoc.ts
Normal file
10
tests/cases/fourslash/quickInfoUniqueSymbolJsDoc.ts
Normal file
@ -0,0 +1,10 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @checkJs: true
|
||||
// @allowJs: true
|
||||
// @filename: ./a.js
|
||||
/////** @type {unique symbol} */
|
||||
////const foo = Symbol();
|
||||
////foo/**/
|
||||
|
||||
verify.baselineQuickInfo();
|
||||
Loading…
x
Reference in New Issue
Block a user