【问题标题】:How to fix Typescript error upon running deno index.ts如何在运行 deno index.ts 时修复 Typescript 错误
【发布时间】:2021-01-01 20:54:27
【问题描述】:

于是我开始学习 Deno。安装 Deno 后(我在 WSL 中使用 Curl curl -fsSL https://deno.land/x/install/install.sh | sh),我想运行服务器。一旦运行deno run index.ts,我得到这些typescript 错误。

$ deno run index.ts 
Compile file:///C:/Users/User/Works/tw_revamp_deno_server/index.ts
error TS2304: Cannot find name 'TransformStream'.
  const res = new TransformStream<Promise<R>, R>({
                  ~~~~~~~~~~~~~~~
    at https://deno.land/std@0.69.0/async/pool.ts:18:19

error TS2304: Cannot find name 'TransformStreamDefaultController'.
      controller: TransformStreamDefaultController<R>,
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/std@0.69.0/async/pool.ts:21:19

error TS2322: Type 'Uint8Array | undefined' is not assignable to type 'Uint8Array | null'.
  Type 'undefined' is not assignable to type 'Uint8Array | null'.
    return line;
    ~~~~~~~~~~~~
    at https://deno.land/std@0.69.0/textproto/mod.ts:149:5

Found 3 errors.

我的 index.ts 文件很简单,与给出的示例类似。

import { serve } from "https://deno.land/std@0.69.0/http/server.ts";
const s = serve({ port: 8000 });
console.log("http://localhost:8000/");
for await (const req of s) {
  req.respond({ body: "Hello World\n" });
}

任何人都遇到过类似的错误并且知道如何解决。随意回复。谢谢

【问题讨论】:

    标签: typescript deno


    【解决方案1】:

    我认为您可以尝试使用--no-check 标志禁用类型检查,使用此选项也有助于加快启动速度。

    $ deno run --no-check index.ts
    

    【讨论】:

      猜你喜欢
      • 2015-10-31
      • 2021-04-19
      • 1970-01-01
      • 2021-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-11
      • 2023-04-09
      相关资源
      最近更新 更多