1

我正在尝试使用 Typescript 的新引用功能创建示例纱线工作区存储库:

https://github.com/tommedema/serverless-mono-example/tree/feature/external-types

当外部库没有类型定义时,应该可以手动添加这些。到目前为止我所做的:

  1. 创建了一个packages/types工作区
  2. packages/types/camelcase在文件中添加了一个示例index.d.ts

    declare module 'camelcase' { export default function camelCase( strs: string | string[], options: { pascalCase?: boolean } ): string }

  3. 更新了一个依赖包以有一个对类型包packages/randomtsconfig.json新引用:

    { "extends": "../../tsconfig.settings.json", "compilerOptions": { "outDir": "dist", "rootDir": "src" }, "references": [ { "path": "../types" } ] }

  4. 更新typeRootstsconfig.settings.json

    "typeRoots": [ "./node_modules/@types", "./packages/types" ],

然而,尽管设置了引用和typeRoots,打字稿无法找到类型定义:

[ts]
Could not find a declaration file for module 'camelcase'. '/Users/tommedema/projects/vg/demos/serverless-mono-example/node_modules/camelcase/index.js' implicitly has an 'any' type.
  Try `npm install @types/camelcase` if it exists or add a new declaration (.d.ts) file containing `declare module 'camelcase';`

我对 typeroots 的使用无效吗?使用引用来实现这一点有意义吗?为什么打字稿找不到类型定义?

4

0 回答 0