首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WebXR typescript支持

WebXR typescript支持
EN

Stack Overflow用户
提问于 2021-01-11 16:03:28
回答 2查看 287关注 0票数 1

我想尝试一下webxr,并设置了一个typescript项目。根据WebXR的说法

我应该做以下事情:

代码语言:javascript
复制
const supported = await navigator.xr.isSessionSupported('immersive-vr');

在我的typescript设置中,navigator.xr显示为error。

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

代码语言:javascript
复制
{
    "compilerOptions": {
        "outDir": "./dist/",
        "noImplicitAny": true,
        "module": "esNext",
        "target": "es6",
        "allowJs": true,
        "moduleResolution": "node"
    },
    "exclude": [
        "./node_modules"
    ],
}
EN

回答 2

Stack Overflow用户

发布于 2021-01-18 17:21:24

您需要为WebXR运行,运行类似于add definitionssuch as these ones.的内容,然后导入类型:

代码语言:javascript
复制
import type { Navigator } from 'webxr';

相关信息:

票数 4
EN

Stack Overflow用户

发布于 2021-07-18 03:55:10

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

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

然后使用以下命令调用xr:

代码语言:javascript
复制
const xr = (navigator as any)?.xr as XRSystem;
xr.requestSession('immersive-vr', {optionalFeatures: ['hand-tracking']})
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65663229

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档