gpt4 book ai didi

typescript - 在 whatwg-fetch 类型声明文件中找不到名称 'Symbol'

转载 作者:搜寻专家 更新时间:2023-10-30 20:32:58 32 4
gpt4 key购买 nike

位于 dt~whatwg-fetch 的 d.ts 文件包含以下声明。

declare class Headers {
// other code ommited
[Symbol.iterator](): IterableIterator<[string, string]>;
}

我们尝试创建一个变通接口(interface)但没有成功。以下均无效。什么会?

interface Symbol {}

interface Symbol<T> {}

interface Symbol {
iterator: IterableIterator<[string, string]>
}

interface Symbol<T> {
iterator: IterableIterator<[string, string]>
}

编辑

我们已经看到了 Typescript Cannot find name 'IterableIterator'并且建议以 es6 为目标。那是必需的吗?

http://www.typescriptlang.org/docs/handbook/iterators-and-generators.html

最佳答案

SymbolES6 的新功能,因此您需要将编译器定位到它。
为此,请指定 the compiler options 中的目标是 “es6”

Symbol 的定义可以在 the lib.es6.d.ts 中找到(虽然它在 default lib.d.ts 中丢失了)


编辑

您可以自己填充该部分,只需从lib.es6.d.ts 文件中复制所需的部分并将其放入您自己的文件中并引用它。

我复制了您发布的代码所需的内容,它在 this playground 中.
它可能比实际需要的要多,所以尝试一下。

关于typescript - 在 whatwg-fetch 类型声明文件中找不到名称 'Symbol',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39280012/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com