TS2304 error TS2304: Cannot find name ‘world’.
Broken Code ❌ 1 console .log (world.name );
Fixed Code ✔️ It can happen that TypeScript does not know about your global objects because those may be injected from an unknown runtime environment or third-party JavaScript library. The easiest way to let TypeScript know about this is to declare the ambience (ambient context ):
1 2 3 4 5 declare var world : { name : string ; };console .log (world.name );
error TS2304: Cannot find name ‘Promise’
Broken Code ❌ 1 2 3 4 5 6 7 8 9 public load_prekey (prekey_id : number ): Promise <Proteus .keys .PreKey > { return new Promise ((resolve ) => { resolve (42 ); }); }
Fixed Code ✔️ Install es6-promise
type definitions with the typings tool.
1 typings install dt~es6-promise --global --save
Adding the following line to the beginning of every file using definitions from es6-promise
.
1 2 3 4 5 6 7 8 9 10 11 ...public load_prekey (prekey_id : number ): Promise <Proteus .keys .PreKey > { return new Promise ((resolve ) => { resolve (42 ); }); } ...
error TS2304: Cannot find name ‘Promise’
Broken Code ❌ 1 const UUID = require ('uuidjs' );
Fixed Code ✔️ 1 npm install @types/node --save-dev
error TS2304: Cannot find name ‘FC’.
Broken Code ❌ 1 2 3 4 5 import React from 'react' ;const App : FC = (): JSX .Element => { return <> </> ; };
Fixed Code ✔️ 1 2 3 4 5 import React , {FC } from 'react' ;const App : FC = (): JSX .Element => { return <> </> ; };