Type definition for navigator.userAgentData
$ npm i -D user-agent-data-types
Add a TypesScript triple-slash directive as follows in any code-containing '.ts' file you want these types to be available in:
// Add data types to window.navigator for use in this file. See https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html#-reference-types- for more info.
/// <reference types="user-agent-data-types" />
console.log(window.navigator.userAgentData) // no type error!
Create a .d.ts
file anywhere in your project so that it is visible to TypeScript according to your tsconfig.json
settings. For
example, it could be at src/global.d.ts
or src/user-agent-data-types.d.ts
.
Add a TypesScript triple-slash directive as follows:
// Add data types to window.navigator ambiently for implicit use in the entire project. See https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html#-reference-types- for more info.
/// <reference types="user-agent-data-types" />
This exposes the types ambiently so they are available without any import
or require
statements. TypeScript will simply know about them everywhere.
Important: do not add any import
or export
statements to this file, or it will stop working ambiently. Doing that
changes it in TypeScript's view from a "script" to a "module", and the rules about ambient types change in that case.
This project is licensed under the MIT License.