From c8b80a3f4b463c3e758939f2e3e795a98063f614 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 12 Nov 2026 19:56:55 -0800 Subject: [PATCH] Suggest the ES2015 library for missing Symbol references The missing-library hint matches source identifier text. The spelling ast.Symbol can never match the global Symbol identifier, so missing Symbol references fall back to generic name and shorthand errors. Match Symbol itself so value, shorthand, and type references receive the existing ES2015 library guidance. --- tsc/internal/checker/checker.go | 2 +- .../missingSymbolLibraryDiagnostic.errors.txt | 27 +++++++++++ .../missingSymbolLibraryDiagnostic.js | 23 ++++++++++ .../missingSymbolLibraryDiagnostic.symbols | 45 +++++++++++++++++++ .../missingSymbolLibraryDiagnostic.types | 27 +++++++++++ .../missingSymbolLibraryDiagnostic.ts | 16 +++++++ 6 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 tsc/testdata/baselines/reference/compiler/missingSymbolLibraryDiagnostic.errors.txt create mode 100644 tsc/testdata/baselines/reference/compiler/missingSymbolLibraryDiagnostic.js create mode 100644 tsc/testdata/baselines/reference/compiler/missingSymbolLibraryDiagnostic.symbols create mode 100644 tsc/testdata/baselines/reference/compiler/missingSymbolLibraryDiagnostic.types create mode 100644 tsc/testdata/tests/cases/compiler/missingSymbolLibraryDiagnostic.ts diff --git a/tsc/internal/checker/checker.go b/tsc/internal/checker/checker.go index f1e5564580f3c..9bb26b5e70182 100644 --- a/tsc/internal/checker/checker.go +++ b/tsc/internal/checker/checker.go @@ -14237,7 +14237,7 @@ func (c *Checker) getCannotFindNameDiagnosticForName(node *ast.Node) *diagnostic return core.IfElse(c.compilerOptions.UsesWildcardTypes(), diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun, diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun_and_then_add_bun_to_the_types_field_in_your_tsconfig) - case "Map", "Set", "Promise", "ast.Symbol", "WeakMap", "WeakSet", "Iterator", "AsyncIterator", "SharedArrayBuffer", "Atomics", "AsyncIterable", + case "Map", "Set", "Promise", "Symbol", "WeakMap", "WeakSet", "Iterator", "AsyncIterator", "SharedArrayBuffer", "Atomics", "AsyncIterable", "AsyncIterableIterator", "AsyncGenerator", "AsyncGeneratorFunction", "BigInt", "Reflect", "BigInt64Array", "BigUint64Array": return diagnostics.Cannot_find_name_0_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_1_or_later case "await": diff --git a/tsc/testdata/baselines/reference/compiler/missingSymbolLibraryDiagnostic.errors.txt b/tsc/testdata/baselines/reference/compiler/missingSymbolLibraryDiagnostic.errors.txt new file mode 100644 index 0000000000000..b2c2ffa3bef4a --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/missingSymbolLibraryDiagnostic.errors.txt @@ -0,0 +1,27 @@ +missingSymbolLibraryDiagnostic.ts(12,1): error TS2583: Cannot find name 'Symbol'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later. +missingSymbolLibraryDiagnostic.ts(13,21): error TS2583: Cannot find name 'Symbol'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later. +missingSymbolLibraryDiagnostic.ts(14,22): error TS2583: Cannot find name 'Symbol'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later. + + +==== missingSymbolLibraryDiagnostic.ts (3 errors) ==== + interface Array {} + interface Boolean {} + interface Function {} + interface CallableFunction extends Function {} + interface NewableFunction extends Function {} + interface IArguments {} + interface Number {} + interface Object {} + interface RegExp {} + interface String {} + + Symbol("value"); + ~~~~~~ +!!! error TS2583: Cannot find name 'Symbol'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later. + const shorthand = { Symbol }; + ~~~~~~ +!!! error TS2583: Cannot find name 'Symbol'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later. + type MissingSymbol = Symbol; + ~~~~~~ +!!! error TS2583: Cannot find name 'Symbol'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2015' or later. + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/missingSymbolLibraryDiagnostic.js b/tsc/testdata/baselines/reference/compiler/missingSymbolLibraryDiagnostic.js new file mode 100644 index 0000000000000..db19ca1dc9338 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/missingSymbolLibraryDiagnostic.js @@ -0,0 +1,23 @@ +//// [tests/cases/compiler/missingSymbolLibraryDiagnostic.ts] //// + +//// [missingSymbolLibraryDiagnostic.ts] +interface Array {} +interface Boolean {} +interface Function {} +interface CallableFunction extends Function {} +interface NewableFunction extends Function {} +interface IArguments {} +interface Number {} +interface Object {} +interface RegExp {} +interface String {} + +Symbol("value"); +const shorthand = { Symbol }; +type MissingSymbol = Symbol; + + +//// [missingSymbolLibraryDiagnostic.js] +"use strict"; +Symbol("value"); +const shorthand = { Symbol }; diff --git a/tsc/testdata/baselines/reference/compiler/missingSymbolLibraryDiagnostic.symbols b/tsc/testdata/baselines/reference/compiler/missingSymbolLibraryDiagnostic.symbols new file mode 100644 index 0000000000000..031f8fe18f723 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/missingSymbolLibraryDiagnostic.symbols @@ -0,0 +1,45 @@ +//// [tests/cases/compiler/missingSymbolLibraryDiagnostic.ts] //// + +=== missingSymbolLibraryDiagnostic.ts === +interface Array {} +>Array : Symbol(Array, Decl(missingSymbolLibraryDiagnostic.ts, 0, 0)) +>T : Symbol(T, Decl(missingSymbolLibraryDiagnostic.ts, 0, 16)) + +interface Boolean {} +>Boolean : Symbol(Boolean, Decl(missingSymbolLibraryDiagnostic.ts, 0, 21)) + +interface Function {} +>Function : Symbol(Function, Decl(missingSymbolLibraryDiagnostic.ts, 1, 20)) + +interface CallableFunction extends Function {} +>CallableFunction : Symbol(CallableFunction, Decl(missingSymbolLibraryDiagnostic.ts, 2, 21)) +>Function : Symbol(Function, Decl(missingSymbolLibraryDiagnostic.ts, 1, 20)) + +interface NewableFunction extends Function {} +>NewableFunction : Symbol(NewableFunction, Decl(missingSymbolLibraryDiagnostic.ts, 3, 46)) +>Function : Symbol(Function, Decl(missingSymbolLibraryDiagnostic.ts, 1, 20)) + +interface IArguments {} +>IArguments : Symbol(IArguments, Decl(missingSymbolLibraryDiagnostic.ts, 4, 45)) + +interface Number {} +>Number : Symbol(Number, Decl(missingSymbolLibraryDiagnostic.ts, 5, 23)) + +interface Object {} +>Object : Symbol(Object, Decl(missingSymbolLibraryDiagnostic.ts, 6, 19)) + +interface RegExp {} +>RegExp : Symbol(RegExp, Decl(missingSymbolLibraryDiagnostic.ts, 7, 19)) + +interface String {} +>String : Symbol(String, Decl(missingSymbolLibraryDiagnostic.ts, 8, 19)) + +Symbol("value"); +const shorthand = { Symbol }; +>shorthand : Symbol(shorthand, Decl(missingSymbolLibraryDiagnostic.ts, 12, 5)) +>Symbol : Symbol(Symbol, Decl(missingSymbolLibraryDiagnostic.ts, 12, 19)) + +type MissingSymbol = Symbol; +>MissingSymbol : Symbol(MissingSymbol, Decl(missingSymbolLibraryDiagnostic.ts, 12, 29)) +>Symbol : Symbol(Symbol) + diff --git a/tsc/testdata/baselines/reference/compiler/missingSymbolLibraryDiagnostic.types b/tsc/testdata/baselines/reference/compiler/missingSymbolLibraryDiagnostic.types new file mode 100644 index 0000000000000..550e7637afa0d --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/missingSymbolLibraryDiagnostic.types @@ -0,0 +1,27 @@ +//// [tests/cases/compiler/missingSymbolLibraryDiagnostic.ts] //// + +=== missingSymbolLibraryDiagnostic.ts === +interface Array {} +interface Boolean {} +interface Function {} +interface CallableFunction extends Function {} +interface NewableFunction extends Function {} +interface IArguments {} +interface Number {} +interface Object {} +interface RegExp {} +interface String {} + +Symbol("value"); +>Symbol("value") : any +>Symbol : any +>"value" : "value" + +const shorthand = { Symbol }; +>shorthand : { Symbol: any; } +>{ Symbol } : { Symbol: any; } +>Symbol : any + +type MissingSymbol = Symbol; +>MissingSymbol : Symbol + diff --git a/tsc/testdata/tests/cases/compiler/missingSymbolLibraryDiagnostic.ts b/tsc/testdata/tests/cases/compiler/missingSymbolLibraryDiagnostic.ts new file mode 100644 index 0000000000000..976eb0510955d --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/missingSymbolLibraryDiagnostic.ts @@ -0,0 +1,16 @@ +// @noLib: true + +interface Array {} +interface Boolean {} +interface Function {} +interface CallableFunction extends Function {} +interface NewableFunction extends Function {} +interface IArguments {} +interface Number {} +interface Object {} +interface RegExp {} +interface String {} + +Symbol("value"); +const shorthand = { Symbol }; +type MissingSymbol = Symbol;