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

如何配置tsconfig.json让IDE识别AssemblyScript自定义库类型

解决方法

要让VSCode自动识别./lib/types/index.d.ts中的全局类型(无需手动导入),只需修改./assembly/tsconfig.json的编译器配置:

修改后的tsconfig.json

{
  "extends": "assemblyscript/std/assembly.json",
  "include": [
    "./**/*.ts"
  ],
  "compilerOptions": {
    "typeRoots": [
      "../lib/types",
      "./node_modules/@types"
    ],
    "types": ["index"]
  }
}

关键配置说明

  • typeRoots:扩展TypeScript的类型搜索根目录,除默认的node_modules/@types外,加入自定义的../lib/types目录,让TypeScript识别该目录下的类型包(你已通过../lib/types/package.json指定了类型入口)。
  • types:显式指定要加载的类型包名称,这里的index对应../lib/types/package.json中types字段指向的index.d.ts,确保该文件中的全局类型(如Room命名空间)在assembly目录的所有TS文件中自动可用。

额外注意事项

确保index.d.ts中的类型声明是全局作用域的,避免使用export关键字。例如:

declare namespace Room {
  function describe(message: string): void;
}

完成上述配置后,VSCode就会自动识别Room等全局类型,不会再抛出"Cannot find name 'Room'"的错误。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 22:42:44