Typescript声明了javascript外部模块

时间:2016-10-14 18:32:58

标签: javascript node.js typescript

所以,我是TypeScript的新手,我想将一个非常小的NodeJS项目转换为TypeScript。在那个项目中,我使用了一些在@types范围内有定义的npm模块,但是其他模块没有。

所以,我想我会在自己的项目中为自己创建这些声明,而不必更改这些第三方模块。但是,无论我将.d.ts文件放在何处,TypeScript似乎都无法识别它。

的src / typings.d.ts

import stream = require( 'stream' );
import http = require( 'http' );

declare module "flatten" {
    function flatten ( ...arrays : any[] ) : any[];

    export = flatten;
}

declare module "got" {
    //...
}

然后当我尝试使用模块展平时,例如:

的src / manager.ts

import flatten = require( 'flatten' );
//...

我收到错误:

src/manager.ts(1,27): error TS2307: Cannot find module 'flatten'.

我的 tsconfig.json 如下所示:

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "noImplicitAny": true,
        "sourceMap": true,
        "outDir": "lib/" 
    },
    "include": [
        "src/**/*"
    ],
    "exclude": [
        "node_modules",
        "**/*.spec.ts"
    ]
}

0 个答案:

没有答案