0
我有一個打字稿應用程序。它看起來像這樣:TypeScript ReferenceError:未定義
Salon.ts
export class Salon {
clients: Client [];
constructor() {
this.clients = [];
}
public addClient(c: Client) {
this.clients.push(c);
}}
Client.ts
class Client {
name: string;
surname: string;
constructor(name, surname){
this.name = name;
this.surname = surname;
}}
在我的服務器上的文件Serv.ts我想要得到與客戶端的信息後請求並將其添加到客戶端陣列:
import {Salon} from "./Salon.js";
s: Salon = new Salon();
app.post("/addClient", (req, res) => {
if (req.query.name === undefined | req.query.surname=== undefined){
res.status(400);
res.setHeader("Content-Type", "text/html; charset=utf-8");
res.end("Your name and surname please");
} else {
console.log(req.query.name, req.query.age);
s.addClient(new Client(req.query.name, req.query.surname));
}
});
而當我運行我的應用程序,並試圖發出請求後,它給了我一個錯誤「ReferenceError:s未定義」。 我該如何處理?