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
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
Share Improve this question asked Mar 20, 2020 at 13:54 PmmZenhaPmmZenha 1853 silver badges10 bronze badges 1- See Also: Property 'share' does not exist on type 'Navigator' – KyleMit ♦ Commented Jul 5, 2021 at 19:32
1 Answer
Reset to default 9You have to add option to your tsconfig.json file.
Add dom to pilerOptions.lib array like here:
{
"pilerOptions": {
"lib": [
"dom"
]
}
}
This option will add necessary typings for DOM API.