Javascript 使用TypeScript导入自定义声明文件

Javascript 使用TypeScript导入自定义声明文件,javascript,typescript,visual-studio-code,Javascript,Typescript,Visual Studio Code,对于名为foo的npm包,我有下面的TypeScript声明(为了本例的缘故,我们假设它没有任何我可以提取的声明文件) declare module "foo" { export function getPerpetualEnergy(): any[]; export function endWorldHunger(n: boolean): void; } 我已将该声明放在/typings/foo.d.ts文件中,并将我的typeroot文件夹更新到下面(在/tsconfig.

对于名为
foo
的npm包,我有下面的TypeScript声明(为了本例的缘故,我们假设它没有任何我可以提取的声明文件)

declare module "foo" {
    export function getPerpetualEnergy(): any[];
    export function endWorldHunger(n: boolean): void;
}
我已将该声明放在
/typings/foo.d.ts
文件中,并将我的
typeroot
文件夹更新到下面(在
/tsconfig.json
文件中):

我尝试从
.ts
使用它,如下所示:

import * as foo from 'foo';
foo.endWorldHunger(true);
然而,它无法解决这一问题。在VS代码中,它也在向我抱怨(因为考虑到我的没有mplicitany:true

我已将我的消耗量改为以下,结果是:

/// <reference path="../../typings/foo.d.ts"/>
import * as foo from 'foo';
foo.endWorldHunger(true);
//
从“foo”导入*作为foo;
foo.endWorldHunger(真实);
我真的需要那个
参考
声明吗?我希望我不会这样做,因为我已经将
/typings
文件夹指定为我的
typeroot
之一,但可能是我配置错了。有没有想过我做错了什么

我使用的是TypeScript 2.2.1


用作
typeroot
的目录应该看起来像
node\u modules
目录,也就是说,
foo
的声明文件应该位于
typings/foo
文件夹中,并命名为
index.d.ts
(或者您应该在
typings/foo
中使用
types
属性将
package.json
指向声明文件)

/// <reference path="../../typings/foo.d.ts"/>
import * as foo from 'foo';
foo.endWorldHunger(true);