2
正如所說的Node.js的文檔,http.IncomingMessage
is a class,而不是一個接口。那麼爲什麼在DefinitelyTyped http.IncomingMessage
defined as interface?爲什麼在DefinitelyTyped`http.IncomingMessage`定義爲接口,而不是類?
[ts] Property 'IncomingMessage' does not exist on type 'typeof "http"'.
我做錯了什麼:
現在在我的代碼,我不能做到這一點:
import * as http from 'http';
let Request = http.IncomingMessage;
打字稿錯誤?
其類,那麼你應該使用它想:'讓請求= http.IncomingMessage();' – ranakrunal9
@ ranakrunal9,no,'http.IncomingMessage'定義爲TypeScript接口,所以接口不能調用構造函數。 – ktretyak
因此,爲了定義'http.IncomingMessage'類型的變量,你應該這樣做:'let Request:http.IncomingMessage;' – ranakrunal9