最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to use navigator and location DOM variables in TypeScript - Stack Overflow

programmeradmin6浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 9

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

发布评论

评论列表(0)

  1. 暂无评论