安装没有打字的npm包

时间:2016-11-29 05:52:53

标签: javascript typescript npm

我正在使用Typescript 2.1。我正在尝试安装没有打字( Source faultPayload = new StringSource( "<SOAP-ENV:Fault xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:v1=\"http://domain/schema/common/fault\">" + "<faultcode>SOAP-ENV:Server</faultcode>" + "<faultstring xml:lang=\"en\">fault</faultstring>" + "<detail>" + "<v1:custompayload>" + "<v1:element1>element1</v1:element1>" + "<v1:element2>element2</v1:element2>" + "</v1:custompayload>" + "</detail>" + "</SOAP-ENV:Fault>"); mockWebServiceServer.expect(payload(requestPayload)) .andRespond(withPayload(faultPayload)); )的npm包。

如果我这样做:

reactable typescript抱怨找不到这个模块。

如果我这样做:

import * as Reactable from 'reactable'打字稿抱怨const Reactable = require('reactable')被禁止。

如果我使用另一篇文章中建议的奇怪语法:

require typescript抱怨import Reactable = require('reactable');分配不能用于定位es2015模块。

有没有办法导入没有打字的npm包?

1 个答案:

答案 0 :(得分:2)

您需要声明有关您正在使用的内容。 例如

declare module "reactable" {
    interface ReactableProps {
        ....
    }

    interface ReactableState {
        ....
    }

    class reactable extends React.Component< ReactableProps, ReactableState> { }
}

您可以从您正在使用的内容开始,并需要IDE支持,并慢慢添加内容。

您可以查看Writing Declaration Files了解有关如何操作的更多信息。