我使用WebStorm,并编写nodeJS应用程序
enabled node js support('Node.js Core library is enabled'选项)
导入并启用distinctTyped:node-DefinitelyTyped
(。WebStorm2016.2 / config / javascript / extLibs / http_github.com_borisyankov_DefinitelyTyped_raw_master_node_node.d.ts)
例如我想要http.ServerResponse
的智慧
在.d.ts文件中我有类似的东西:
declare module "http" {
//...
export interface ServerResponse extends events.EventEmitter, stream.Writable {
//...
writeHead(statusCode: number, headers?: any): void;
//...
}
}
现在我想在我的js代码中获取方法自动缩放:
/**
* @param {http.ServerResponse} response such jsdoc does not work, what type is it?
*/
function handleResponse(response){
response.writeHead(200); //here i want the autocompletion
}
问题:如何记录js / use .d.ts以获得正确的代码完成?
答案 0 :(得分:0)
您忘记了参数(响应)。
/**
* @param {http.ServerResponse} response Now it should work
*/
...
答案 1 :(得分:0)
尝试
/**
* @param {module:http.ServerResponse}
*/