Typescript编译器工作,但Javascript结果错误
首先,我想向您展示我的目录树:Typescript编译器工作,但Javascript结果错误,javascript,node.js,typescript,express,compiler-warnings,Javascript,Node.js,Typescript,Express,Compiler Warnings,首先,我想向您展示我的目录树: \__ root \__ node_modules \__src \__ dir1 \__ index.ts \__ package.json \__ deploy.config //not important here \__ dir2 //architecture like dir1 \__
\__ root
\__ node_modules
\__src
\__ dir1
\__ index.ts
\__ package.json
\__ deploy.config //not important here
\__ dir2 //architecture like dir1
\__ dir3
\__ ...
\__ package.json
\__ //some configuration files
我试图通过添加Typescript在我的NodeJS项目中添加类型。为此,我在根文件夹中安装了很多东西:
'use strict'
const toolPath = process.env.TOOLPATH || '';
import express, { Response, Request } from 'express';
var app = express();
app.get('/test', async (req: Request, res: Response) => {
res.send("Hello world !");
});
module.exports = {
app
};
'use strict'
const toolPath = process.env.TOOLPATH || '';
import express, { Response, Request } from 'express';
var app = express();
app.get('/test', async (req: Request, res: Response) => {
res.send("Hello world !");
});
module.exports = {
app
};
为了测试typescript编译器,我在dir1文件夹中使用了以下命令:npx tsc index.ts
,结果如下:
index.ts(9,28): error TS1005: ',' expected.
index.ts(9,42): error TS1005: ',' expected.
index.ts(9,54): error TS1005: ',' expected.
index.ts(10,8): error TS1005: ':' expected.
index.ts(10,30): error TS1005: ',' expected.
我不知道为什么我在index.ts中有一些错误
已创建index.js文件,但其中包含错误:
'use strict';
var toolPath = process.env.TOOLPATH || '';
var express_1 = require('express');
var app = express_1["default"]();
app.get('/test', async(req, express_1.Request, res, express_1.Response), {
res: .send("Hello world !") //<--- ERROR THERE
});
module.exports = {
app: app
};
“严格使用”;
var toolPath=process.env.toolPath | |“”;
var express_1=需要(“express”);
var app=express_1[“default”]();
app.get('/test',异步(req,express\u 1.Request,res,express\u 1.Response){
res:.send(“Hello world!”)/查看以下内容:
npm i-D类型脚本
npmi-D@types/node
npm i-D@types/express
您只安装了node和express的类型
通过安装这些依赖项进行修复,就像安装了typescript;)