简体   繁体   English

导入节点模块的TS类型

[英]Import TS typings for Node module

I'm trying to import Typescript typings for node-soap. 我正在尝试导入node-soap的Typescript类型。

I need to access an WSDL API from a React app with Typescript. 我需要从带有Typescript的React应用程序访问WSDL API。 The node-soap module looks like a great option, but I need Typescript support. node-soap模块看起来是一个很好的选择,但我需要Typescript支持。 On the node-soap github, I see a file with all the Typescript typings, but I don't know how to import them. 在node-soap github上,我看到一个包含所有Typescript类型的文件,但我不知道如何导入它们。 I copied "soap.d.ts" into the node_modules/node-soap directory, but VSCode still says I need to declare the module. 我将“soap.d.ts”复制到node_modules / node-soap目录中,但VSCode仍然说我需要声明模块。 I'm not sure where to do that. 我不知道该怎么做。

I'm still pretty new to Typescript. 我对Typescript仍然很陌生。 With previous modules, I've relied on using @types, and I haven't found concrete documentation on how to set up typings when there is @types aren't present. 使用以前的模块,我依赖于使用@types,并且我没有找到有关如何在没有@types时设置打字的具体文档。

https://github.com/vpulim/node-soap/blob/7d912aad2102aced9751e81e76f4a98a930bd0b9/lib/soap.d.ts https://github.com/vpulim/node-soap/blob/7d912aad2102aced9751e81e76f4a98a930bd0b9/lib/soap.d.ts

Can anyone point me in the right direction? 谁能指出我正确的方向?

Are you sure you are using the right module? 您确定使用的是正确的模块吗? The module that has the declaration file soap.d.ts should be installed with: 具有声明文件soap.d.ts的模块应安装为:

npm install soap

Then at least for me the following is working, ie, IntelliSense is displaying the expected parameter types for createClient : 然后至少对我来说,以下是有效的,即IntelliSense正在显示createClient的预期参数类型:

 import * as soap from 'soap';

 var url = 'http://example.com/wsdl?wsdl';
 var args = {name: 'value'};
 soap.createClient(url, function(err, client) { });

The module resolution is explained here . 这里解释模块分辨率。

For module soap , package.json defines "types": "./lib/soap.d.ts" . 对于模块soappackage.json定义"types": "./lib/soap.d.ts"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM