我想尝试一下webxr,并设置了一个typescript项目。根据WebXR的说法
我应该做以下事情:
const supported = await navigator.xr.isSessionSupported('immersive-vr');在我的typescript设置中,navigator.xr显示为error。


我想知道如何为webxr设置typescript。我的tsconfig看起来像这样:
{
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": true,
"module": "esNext",
"target": "es6",
"allowJs": true,
"moduleResolution": "node"
},
"exclude": [
"./node_modules"
],
}发布于 2021-01-18 17:21:24
您需要为WebXR运行,运行类似于add definitions:such as these ones.的内容,然后导入类型:
import type { Navigator } from 'webxr';相关信息:
发布于 2021-07-18 03:55:10
在命令行中使用npm i -D @types/webxr安装webxr的类型。
然后使用import type { XRSystem } from 'webxr';在ts文件中导入XRSystem (注意导入中的type word )。
然后使用以下命令调用xr:
const xr = (navigator as any)?.xr as XRSystem;
xr.requestSession('immersive-vr', {optionalFeatures: ['hand-tracking']})https://stackoverflow.com/questions/65663229
复制相似问题