簡體   English   中英

使用Typescript中的節點靜態獲取Server.serve狀態代碼

[英]Getting the Server.serve status code using node-static in Typescript

我正在嘗試在Typescript中編寫一些節點靜態示例代碼,但出現了錯誤

類型“錯誤”不存在屬性“狀態”

這是我的錯誤代碼

import * as server from 'node-static';
import * as http from "http"

var fileServer = new server.Server('./images');

http.createServer(function (request, response) {
    request.addListener('end', function () {
        var callback: server.Callback;
        callback = function (e: Error) {
            if (e && (e.status === 404)) { // Error in this line 
                fileServer.serveFile('/not-found.html', 404, {}, request, response);
            }
        };
        fileServer.serve(request, response, callback)
    }).resume();
}).listen(8080);

錯誤的類型為字符串,並且為堆棧跟蹤,因此明確了打字錯誤的原因。
我的問題是如何獲取狀態碼。

原始的JavaScript代碼在這里

看來@types for node-static是錯誤的。 鏈接

特別是因為Callback是一個也可以具有res對象的函數。

您可以隨時退回到any

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM