- Error
- Reported by the type checker
TS2592
Cannot find name '{0}'. Do you need to install type definitions for jQuery? Try `npm i --save-dev @types/jquery` and then add 'jquery' to the types field in your tsconfig.
jQuery's $ or jQuery global is used without its type definitions. Install @types/jquery and add "jquery" to the types option.
What it means
The name is jQuery's global ($ or jQuery), and no jQuery type definitions are loaded.
Example
$(".item");
export {};
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(1,1): error TS2592: Cannot find name '$'. Do you need to install type definitions for jQuery? Try `npm i --save-dev @types/jquery` and then add 'jquery' to the types field in your tsconfig.
Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.
How to fix
- Install the type definitions:
npm i --save-dev @types/jquery. - If
tsconfig.jsonsetstypes, add"jquery"to it. - Or import jQuery as a module instead of relying on the global.