【问题标题】:WebXR typescript supportWebXR 打字稿支持
【发布时间】:2021-04-16 04:21:16
【问题描述】:

我想试验一下 webxr 并设置了一个 typescript 项目。根据WebXR

我应该做以下事情:

const supported = await navigator.xr.isSessionSupported('immersive-vr');

使用我的打字稿设置navigator.xr 显示为错误。

我想知道如何为webxr 设置打字稿。我的tsconfig 看起来像这样:

{
    "compilerOptions": {
        "outDir": "./dist/",
        "noImplicitAny": true,
        "module": "esNext",
        "target": "es6",
        "allowJs": true,
        "moduleResolution": "node"
    },
    "exclude": [
        "./node_modules"
    ],
}

【问题讨论】:

    标签: typescript webxr


    【解决方案1】:

    对于 WebXR,您需要 add definitionssuch as these ones. 类似运行:npm install --save-dev @types/webxr,然后导入类型:

    import type { Navigator } from 'webxr';
    

    相关:

    【讨论】:

      【解决方案2】:

      在您的命令行中使用npm i -D @types/webxrwebxr 安装类型。

      然后使用import type { XRSystem } from 'webxr'; 在您的ts 文件中导入XRSystem(注意导入中的type 字)。

      然后调用 xr:

      const xr = (navigator as any)?.xr as XRSystem;
      xr.requestSession('immersive-vr', {optionalFeatures: ['hand-tracking']})
      

      【讨论】:

        猜你喜欢
        • 2020-04-11
        • 1970-01-01
        • 1970-01-01
        • 2017-11-21
        • 2022-08-24
        • 2015-07-15
        • 2017-08-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多