2016-08-20 204 views
0

我试图写一个声明文件,但在编译我得到的错误出口外包装分型文件是不是一个模块

出口外包装分型文件 “/nativescript-keychain/index.d。 ts'不是一个模块。请联系 软件包作者更新软件包定义。

我正在写它的代码非常简单,所以不知道我哪里出错了。

var setPassword = function (password, appName, account) { 
    SAMKeychain.setPasswordForServiceAccount(password, appName, account); 
    return true; 
}; 

var getPassword = function (appName, account) { 
    return SAMKeychain.passwordForServiceAccount(appName, account); 
}; 

exports.setPassword = setPassword; 
exports.getPassword = getPassword; 

和index.d.ts是

declare module "nativescript-keychain" { 

    export function setPassword(password: string, appName: string, account: string): void; 
    export function getPassword(appName: string, account: string): void; 
} 

回答

0

如果你想为你不应该让他们的全球(环境)的模块提供分型。

所以只是删除declare module,它应该工作。

// index.d.ts 
export function setPassword(password: string, appName: string, account: string): void; 
export function getPassword(appName: string, account: string): void; 

您可以检查作为一个例子ImmutableJS typings

如果你想发布您的分型作为一个单独的d.ts并将其发布到DefinitelyTyped,你应该在你的分型declare module

+0

谢谢你的工作,仍然试图让我的头在一切。 – dottodot

+0

这对于编写'd.ts'文件有很长的篇幅。您可以在[类型文档](https://github.com/typings/typings/blob/master/docs/external-modules.md)上阅读更多内容。 。另外http://stackoverflow.com/questions/34030542/how-to-create-an-external-module-typescript-definition-file-to-include-with-an?rq=1是另一个很好的阅读。 – drinchev

相关问题