javascript - Web-Bluetooth:导航器的自定义类型
问题描述
我正在为我的设备编写一个浏览器应用程序,它将通过蓝牙进行通信。
有人可以帮我打字吗?
我正在尝试访问navigator
对象中的蓝牙属性:
let mobileNavigatorObject: Navigator = navigator;
mobileNavigatorObject.bluetooth.requestDevice(
{
filters: [
{
namePrefix: "My",
}
],
optionalServices: ["service uuid"]
}
)
但我有:error TS2339: Property 'bluetooth' does not exist on type 'Navigator'.
即使在安装 @type/web-bluetooth 之后
有2种来源node_modules/typescript/lib/lib.dom.d.ts
interface Navigator extends NavigatorID, NavigatorOnLine, NavigatorContentUtils, NavigatorStorageUtils, MSNavigatorDoNotTrack, MSFileSaver, NavigatorBeacon, NavigatorConcurrentHardware, NavigatorUserMedia, NavigatorLanguage, NavigatorStorage, NavigatorAutomationInformation {
readonly activeVRDisplays: ReadonlyArray<VRDisplay>;
readonly authentication: WebAuthentication;
readonly cookieEnabled: boolean;
readonly doNotTrack: string | null;
gamepadInputEmulation: GamepadInputEmulationType;
readonly geolocation: Geolocation;
readonly maxTouchPoints: number;
readonly mimeTypes: MimeTypeArray;
readonly msManipulationViewsEnabled: boolean;
readonly msMaxTouchPoints: number;
readonly msPointerEnabled: boolean;
readonly plugins: PluginArray;
readonly pointerEnabled: boolean;
readonly serviceWorker: ServiceWorkerContainer;
readonly webdriver: boolean;
getGamepads(): (Gamepad | null)[];
getVRDisplays(): Promise<VRDisplay[]>;
javaEnabled(): boolean;
msLaunchUri(uri: string, successCallback?: MSLaunchUriCallback, noHandlerCallback?: MSLaunchUriCallback): void;
requestMediaKeySystemAccess(keySystem: string, supportedConfigurations: MediaKeySystemConfiguration[]): Promise<MediaKeySystemAccess>;
vibrate(pattern: number | number[]): boolean;
}
和node_modules/@types/web-bluetooth/index.d.ts
interface Navigator {
bluetooth: Bluetooth;
}
tsConfig:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
}
}
如何选择正确的?
解决方案
推荐阅读
- linker - Fortran 语言绑定错误:为什么不链接到 MPI 库?
- jenkins - 给定一个拉取请求 ID,我如何获取拉取请求的作者?使用 GitHub API?
- adsense - 为什么我的网站没有获得 AdSense 的批准?
- hive - HIVE:优化非分区表到分区表的连接
- javascript - 带边框的复制表格在 Firefox 中不起作用
- android - 在运行时从列表中调用函数序列
- ms-access-2016 - 创建表单的问题在布局视图或表单视图中没有显示,但在设计视图中显示
- ruby-on-rails - 如何将某些值存储在新数组中的 JSON 哈希中?
- php - 向关联数组添加维度
- python - 如何使用 Python 解析相对有组织但没有分隔的文本?