根據教程,這是我第一次嘗試使用打字稿設定節點。下面的代碼導致對該app.listen函式的錯誤建議(見圖)。
import express from 'express';
const app = express();
app.listen(3000)

第一個引數應該是一個埠。當我仍在輸入函式名稱時,這反映在建議中:

指定app型別 asexpress.Application沒有幫助。
我已經安裝了@types/express,@types/node,ts-node并typescript作為開發的依賴。在 中tsconfig.js,我有以下設定:{ "target": "es6", "module": "commonjs", "moduleResolution": "node" }
uj5u.com熱心網友回復:
如listen()您的影像所示,該方法有 6 個多載。帶有 1 個引數的多載首先顯示,因為它是最短的。如果您,在函式內鍵入一個數字和一個,您將看到描述更改為您所期望的。
多載定義如下:
listen(port: number, hostname: string, backlog: number, callback?: () => void): http.Server;
listen(port: number, hostname: string, callback?: () => void): http.Server;
listen(port: number, callback?: () => void): http.Server;
listen(callback?: () => void): http.Server;
listen(path: string, callback?: () => void): http.Server;
listen(handle: any, listeningListener?: () => void): http.Server;
VSC 顯示的提示盡可能接近您輸入的內容。由于您沒有提供任何引數,因此最接近的簽名是只有回呼的簽名。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/315109.html
下一篇:提示用戶只輸入密碼的一部分
