![](/img/trans.png)
[英]Debugging with VSCODE not working in a Webpack + Typescript + no-framework
[英]Vscode not working with Sailsjs Services and typescript
我在sailsjs应用程序中遇到打字稿问题。
我正在使用Typescript编写控制器,并且想在控制器内部使用sailsjs服务,但在VSCODE中遇到语法错误。
MyController.ts
import util = require('util');
import express = require('express');
declare var sails: any;
var count : number = 0;
export function stats(req:any, res:any, next: Function):any {
console.log('TsController.ts');
TestLog.send();
res.status(200).send({});
}
TestLog.js
module.exports = {
send: function(){
console.log("Service is Logging")
}
}
但是VSCODE引发一个错误
[ts]找不到名称“ TestLog”。
顺便说一句,如果我举起应用程序按预期工作
这是因为TypeScript不知道您具有TestLog
它是在JavaScript文件中定义的,并且未导入。
为此,您的“ MVP”修复程序是告诉编译器不要担心:
declare var TestLog: any;
然后,您可以优化此定义以使其更有用...
declare var TestLog: { send(): void };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.