Using chrome extension apis in typescript

That should work fine : https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/chrome/index.d.ts

TIP: make sure you have a reference tag added:

/// <reference path="pathTo/chrome.d.ts"/>


As of typescript 2 (or 2.x, not sure), you should import the chrome types from @types.

in package.json:

"devDependencies": {
    ...
    "@types/chrome": "0.0.35", // or just npm install --save-dev @types/chrome

And in tsconfig:

    "types": [
        //(various types, e.g. jquery, core-js),
        "chrome"
    ]

Types Across Chrome and Firefox

Since the extension API is basically the same across Chrome and Firefox now, you can use @types/chrome for both situations.

1. install

yarn add @types/chrome --dev

2. update tsconfig

{
  "compilerOptions": {
    ....
    "types": ["chrome"]
  }
}

3. Get browser api function

export function getBrowserInstance(): typeof chrome {
  // Get extension api Chrome or Firefox
  const browserInstance = window.chrome || (window as any)['browser'];
  return browserInstance;
}