TS2304

Cannot find name 'world'.

Broken Code ❌

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):

declare var world: {
  name: string;
};
 
console.log(world.name);

Cannot find name 'Promise'

Broken Code ❌

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

typings install dt~es6-promise --global --save

Adding the following line to the beginning of every file using definitions from es6-promise.

/// <reference path='es6-promise.d.ts' />
 
...
 
public load_prekey(prekey_id: number): Promise<Proteus.keys.PreKey> {
  return new Promise((resolve) => {
    resolve(42);
  });
}
 
...

Cannot find name 'Promise'

Broken Code ❌

const UUID = require('uuidjs');

Fixed Code ✔️

npm install @types/node --save-dev

Cannot find name 'FC'.

Broken Code ❌

import React from 'react';
 
const App: FC = (): JSX.Element => {
  return <></>;
};

Fixed Code ✔️

import React, { FC } from 'react';
 
const App: FC = (): JSX.Element => {
  return <></>;
};