不能 运行 使用 Deno 和 Servest 服务器
Can't run server with Deno and Servest
我试图 运行 Deno 和 typescript 中的一个简单服务器,但我一直遇到这个错误:
error: TS2739 [ERROR]: Type '{ localAddr: { transport: "tcp"; hostname: string; port:
number; }; remoteAddr: { transport: "tcp"; hostname: string; port: number; }; rid:
number; close(): void; closeWrite(): Promise<void>; read(p: Uint8Array): Promise<...>;
write(p: Uint8Array): Promise<...>; }' is missing the following properties from type
'Conn': readable, writable
const conn: Deno.Conn = {
~~~~
at https://deno.land/x/servest@v1.3.1/testing.ts:41:9
我使用服务器文档中的这段代码:
// @deno-types="https://deno.land/x/servest@v1.3.1/types/react/index.d.ts"
import React from "https://dev.jspm.io/react/index.js";
// @deno-types="https://deno.land/x/servest@v1.3.1/types/react-dom/server/index.d.ts"
import ReactDOMServer from "https://dev.jspm.io/react-dom/server.js";
import { createApp } from "https://deno.land/x/servest@v1.3.1/mod.ts";
const app = createApp();
app.handle("/", async (req) => {
await req.respond({
status: 200,
headers: new Headers({
"content-type": "text/html; charset=UTF-8",
}),
body: ReactDOMServer.renderToString(
<html>
<head>
<meta charSet="utf-8" />
<title>servest</title>
</head>
<body>Hello Servest!</body>
</html>,
),
});
});
app.listen({ port: 8899 });
我到处搜索都找不到答案,我使用的是 deno v1.19.1
Deno 作为程序依赖树的一部分下载的文件之一如下:
https://deno.land/x/servest@v1.3.1/testing.ts
在错误消息中,您可以看到在对该文件进行类型检查时出现 TypeError,因为 Deno.Conn
缺少 readable
和 writeable
属性。
如果访问https://deno.land/x/servest@v1.3.1/testing.ts#L41 you can see it declares a variable conn
of type Deno.Conn
which does not have these properties indeed. Deno added readable
and writeable
to Deno.Conn in 1.19,那么Servest 1.3.1声明的conn
类型和Deno 1.19声明的Deno.Conn
类型不一样。您可以将此问题的代码告知作者,以便他们进行修复。同时你可以使用 Deno 1.18,这个类型还没有改变。
我试图 运行 Deno 和 typescript 中的一个简单服务器,但我一直遇到这个错误:
error: TS2739 [ERROR]: Type '{ localAddr: { transport: "tcp"; hostname: string; port:
number; }; remoteAddr: { transport: "tcp"; hostname: string; port: number; }; rid:
number; close(): void; closeWrite(): Promise<void>; read(p: Uint8Array): Promise<...>;
write(p: Uint8Array): Promise<...>; }' is missing the following properties from type
'Conn': readable, writable
const conn: Deno.Conn = {
~~~~
at https://deno.land/x/servest@v1.3.1/testing.ts:41:9
我使用服务器文档中的这段代码:
// @deno-types="https://deno.land/x/servest@v1.3.1/types/react/index.d.ts"
import React from "https://dev.jspm.io/react/index.js";
// @deno-types="https://deno.land/x/servest@v1.3.1/types/react-dom/server/index.d.ts"
import ReactDOMServer from "https://dev.jspm.io/react-dom/server.js";
import { createApp } from "https://deno.land/x/servest@v1.3.1/mod.ts";
const app = createApp();
app.handle("/", async (req) => {
await req.respond({
status: 200,
headers: new Headers({
"content-type": "text/html; charset=UTF-8",
}),
body: ReactDOMServer.renderToString(
<html>
<head>
<meta charSet="utf-8" />
<title>servest</title>
</head>
<body>Hello Servest!</body>
</html>,
),
});
});
app.listen({ port: 8899 });
我到处搜索都找不到答案,我使用的是 deno v1.19.1
Deno 作为程序依赖树的一部分下载的文件之一如下:
https://deno.land/x/servest@v1.3.1/testing.ts
在错误消息中,您可以看到在对该文件进行类型检查时出现 TypeError,因为 Deno.Conn
缺少 readable
和 writeable
属性。
如果访问https://deno.land/x/servest@v1.3.1/testing.ts#L41 you can see it declares a variable conn
of type Deno.Conn
which does not have these properties indeed. Deno added readable
and writeable
to Deno.Conn in 1.19,那么Servest 1.3.1声明的conn
类型和Deno 1.19声明的Deno.Conn
类型不一样。您可以将此问题的代码告知作者,以便他们进行修复。同时你可以使用 Deno 1.18,这个类型还没有改变。