How to use navigator and location DOM variables in TypeScript

Viewed 1817

so I'm doing a project that uses react and typescript, however I need to access some DOM variables like navigator and location. However I can access those vars in a JS file but not is TS file. I've been searching but couldn't find any answer. I hope this is not trivial.

Example of a function I called in JS but need it to be in TS:

const { usage, quota } = await navigator.storage.estimate();

Thank you in advance

1 Answers

You have to add option to your tsconfig.json file.

Add dom to compilerOptions.lib array like here:

{
  "compilerOptions": {
        "lib": [
            "dom"
        ]
  }
}

This option will add necessary typings for DOM API.

Related