You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Forge Viewer的DefinitelyTyped声明缺失Profiles等相关类型如何补充?

解决方案

  1. 本地补充临时类型声明
    在项目中新建typings/forge-viewer.d.ts文件,写入以下内容扩展现有类型定义,可根据自己实测的API参数调整字段类型:
import type { Viewer3D } from 'forge-viewer';

declare global {
  namespace Autodesk.Viewing {
    interface ProfileSettings {
      // 内置配置枚举值,可根据实际运行返回值调整类型
      AEC: string;
      clone(settings: Partial<ProfileSettings>): ProfileSettings;
    }

    class Profile {
      constructor(customProfileSettings: Partial<ProfileSettings>);
    }

    interface Viewer3D {
      registerProfile(profile: Profile, profileId: string): void;
      setProfile(profile: string | Profile): void;
      impl: {
        // 三个参数依次为最低FPS、目标FPS、最高FPS
        setFPSTargets(minFps: number, targetFps: number, maxFps: number): void;
      }
    }
  }
}

之后在tsconfig.json的include字段中添加该类型文件的路径,确保TS可以识别到扩展的类型。

  1. 类型校准方法
    如果遇到参数不匹配的情况,可以直接在浏览器控制台运行对应的API,打印出入参要求和返回值结构,调整上面的类型定义即可:
  • 查看ProfileSettings结构:console.dir(Autodesk.Viewing.ProfileSettings)
  • 查看setFPSTargets入参要求:console.log(viewer.impl.setFPSTargets.toString())
  1. 长期方案
    你可以将校验完成的类型定义提交到DefinitelyTyped的forge-viewer类型包,供所有开发者共用。

内容的提问来源于stack exchange,提问作者Vi100

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 12:54:04