打字稿找不到我的类型定义

时间:2019-02-23 16:25:36

标签: typescript

我正在尝试为库中的文件编写自定义定义,但是我不知道如何配置tsconfig以使打字稿编译器使用我的声明文件。这是我的tsconfig.json

{
  "compilerOptions": {
    "target": "es2018",
    "module": "commonjs",
    "lib": ["es2018"],
    "moduleResolution": "node",
    "allowJs": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "noImplicitReturns": true,
    "outDir": "../dist/next",
    "baseUrl": ".",
    "typeRoots": [
      "types",
      "../node_modules/@types"
    ]
  },
  "exclude": [
    "types/**/*"
  ]
}

我正在尝试使用Nextjs构建模块:

https://github.com/zeit/next.js/blob/canary/packages/next/build/index.ts

使用npm安装后,似乎仅在node_modules/next/dist/build/index.js可用。因此,我用以下内容创建了types/next-build.d.ts

declare module 'next/dist/build' {
  export default function build(dir: string, conf: object | null): Promise<void>;
}

然后我运行tsc,它吐出了这个错误:

next/build.ts:1:19 - error TS7016: Could not find a declaration file for module 'next/dist/build'. '/Users/james/projects/next-ts/next/node_modules/next/dist/build/index.js' implicitly has an 'any' type.
  If the 'next' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/next`

1 import build from 'next/dist/build';
                    ~~~~~~~~~~~~~~~~~

如何使打字稿编译器使用build-next.d.ts?这不是typeRoots配置的工作方式吗?

0 个答案:

没有答案
相关问题