fix(56737): unique symbol quick info is different in JS than TS (#56743)

This commit is contained in:
Oleksandr T 2024-01-02 21:34:45 +02:00 committed by GitHub
parent a50f67d347
commit 382de91763
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 143 additions and 4 deletions

View File

@ -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) {

View File

@ -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"
}
]
}
]
}
}
]

View 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.

View 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 */

View 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 */

View File

@ -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

View File

@ -15,7 +15,7 @@ class C {
* @readonly
*/
static readonlyType;
>readonlyType : symbol
>readonlyType : unique symbol
/**
* @type {unique symbol}

View 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 */

View 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();