美文网首页
6 标准库

6 标准库

作者: 9e8aeff1c70c | 来源:发表于2021-05-31 13:32 被阅读0次

Deno提供了一组标准模块,这些模块由核心团队审核,并保证可以与Deno一起使用。

标准库可从以下网址获得:https://deno.land/std/

版本化和稳定性

标准库还不稳定,因此它的版本不同于Deno。有关最新版本的信息,请咨询https://deno.land/std/https://deno.land/std/version.ts.或。每次发布Deno时,都会发布标准库。

我们强烈建议始终使用固定标准库版本的导入,以避免意外更改。例如,不是链接到默认的代码分支(它可能随时更改,可能会导致编译错误或意外行为):

// import the latest release, this should be avoided
import { copy } from "https://deno.land/std/fs/copy.ts";

取而代之的是使用了一个不可变且不会更改的STD库版本:

// imports from v0.95.0 of std, never changes
import { copy } from "https://deno.land/std@0.95.0/fs/copy.ts";

找错

标准库中提供的一些模块使用不稳定的Deno API。

尝试在没有--unstableCLI标志的情况下运行这类模块时,会出现大量的打字错误,这表明当前Deno命名空间中的一些API不存在:

// main.ts
import { copy } from "https://deno.land/std@0.95.0/fs/copy.ts";
copy("log.txt", "log-old.txt");
$ deno run --allow-read --allow-write main.ts
Compile file:///dev/deno/main.ts
Download https://deno.land/std@0.95.0/fs/copy.ts
Download https://deno.land/std@0.95.0/fs/ensure_dir.ts
Download https://deno.land/std@0.95.0/fs/_util.ts
error: TS2339 [ERROR]: Property 'utime' does not exist on type 'typeof Deno'. 'Deno.utime' is an unstable API. Did you forget to run with the '--unstable' flag?
    await Deno.utime(dest, statInfo.atime, statInfo.mtime);
               ~~~~~
    at https://deno.land/std@0.95.0/fs/copy.ts:92:16

TS2339 [ERROR]: Property 'utimeSync' does not exist on type 'typeof Deno'. 'Deno.utimeSync' is an unstable API. Did you forget to run with the '--unstable' flag?
    Deno.utimeSync(dest, statInfo.atime, statInfo.mtime);
         ~~~~~~~~~
    at https://deno.land/std@0.95.0/fs/copy.ts:103:10

要解决这个问题,需要添加--unstable属性标志:

deno run --allow-read --allow-write --unstable main.ts

为了确保接口产生错误是不稳定的,请检查lib.deno.unstable.d.ts的声明。

这个问题应该在不久的将来得到解决。如果您所依赖的特定模块在没有该标志的情况下成功编译,可以随意省略该标志。

相关文章

  • 6 标准库

    Deno提供了一组标准模块,这些模块由核心团队审核,并保证可以与Deno一起使用。 标准库可从以下网址获得:htt...

  • Week6(Boolan)

    c++标准库体系结构与内核分析 c的标准库基本都是由一个个函数组成,而c++标准库由6个紧密关联的part组成 泛...

  • Python | Python笔记(进阶)

    Python学习笔记。包括exception,模块,标准库,pypi等。 6. Exception Excepti...

  • RobotFramework测试库

    一、标准库 一些测试库与Robot Framework一起分发,这些库称为标准库。这些是可用的标准库: Built...

  • Boolan C++标准库 第一周

    C++标准库 第一讲 一、认识headers、版本 1.C++标准库 vs STL C++标准库大于STL(标准...

  • 标准库

    标准库 Python标准库中包含了大量有用的模块,同时也是每个标准的Python安装包中的一部分。熟悉Python...

  • 标准库

    Object 对象 1. Object静态方法 (1) 对象属性模型的相关方法Object.keys() : 获取...

  • 标准库

    C语言的标准库总共分成十五个部分,每个部分用一个头描述。许多编译器都会使用扩展后的库,因此,包含的头通常会多于十五...

  • 标准库

    assert.h 断言

  • 标准库

    数据类型 datetime: 基本日期和时间类型calendar: 与日历相关的一般功能collections: ...

网友评论

      本文标题:6 标准库

      本文链接:https://www.haomeiwen.com/subject/vjuurltx.html