使用严格编译键入无类型导入的定义

时间:2017-06-26 01:58:07

标签: typescript typescript2.0

在导入缺少类型定义的包时,我在使用--strict编译项目时遇到错误。即使我提供自己的定义,我仍然会收到错误。

说我试图使用包untyped-lib

// index.js
import * as Untyped from 'untyped-lib';

我会收到以下错误:

error TS7016: Could not find a declaration file for module 'untyped-lib'. '/Users/faraz/Workspace/project/node_modules/untyped-lib/dist/index.js' implicitly has an 'any' type.

现在让我说我在./mytypes/untyped-lib.d.ts中为文件创建了一个类型定义:

declare module "untyped-lib" {
  const typed: SomeInterface;
  export = typed; 
}

将该目录添加到我的tsconfig.json:

{
    "compilerOptions": {
        ...,
        "typeRoots": [
            "./node_modules/@types",
            "./mytypes"
        ]
    }
}

我仍然收到申报问题。如何向TypeScript提供定义以使错误消失?

0 个答案:

没有答案
相关问题