在 whatwg-fetch 类型声明文件中找不到名称 'Symbol'
Cannot find name 'Symbol' in whatwg-fetch type declaration file
dt~whatwg-fetch 中的 d.ts
文件包含以下声明。
declare class Headers {
// other code ommited
[Symbol.iterator](): IterableIterator<[string, string]>;
}
我们已尝试创建解决方法界面但未成功。 None 以下作品。什么会?
interface Symbol {}
interface Symbol<T> {}
interface Symbol {
iterator: IterableIterator<[string, string]>
}
interface Symbol<T> {
iterator: IterableIterator<[string, string]>
}
编辑
我们已经看到 ,建议以 es6 为目标。那是必需的吗?
http://www.typescriptlang.org/docs/handbook/iterators-and-generators.html
Symbol
是 ES6
的新功能,因此您需要将编译器定位到它。
为此,指定 the compiler options 中的目标是 "es6"
.
Symbol
的定义可以在 the lib.es6.d.ts (while it's missing in the default lib.d.ts)
中找到
编辑
你可以自己填充那个部分,你只需要从 lib.es6.d.ts
文件中复制需要的部分并将其放入你自己的文件中并引用它。
我复制了您发布的代码所需的内容,它位于 this playground。
它可能比实际需要的更多,所以请尝试一下。
帮助我解决问题的是将以下设置添加到 tsconfig.json:
"lib": [
"es6",
"dom"
]
在那之后我又遇到了重复 Promise 声明的错误,但我只是删除了 polyfill 类型定义并且工作正常。
看起来 whatwg-fetch 并不真的需要 ES6 符号,代码可以使用 ES5 回退:
https://github.com/DefinitelyTyped/DefinitelyTyped/issues/11290
dt~whatwg-fetch 中的 d.ts
文件包含以下声明。
declare class Headers {
// other code ommited
[Symbol.iterator](): IterableIterator<[string, string]>;
}
我们已尝试创建解决方法界面但未成功。 None 以下作品。什么会?
interface Symbol {}
interface Symbol<T> {}
interface Symbol {
iterator: IterableIterator<[string, string]>
}
interface Symbol<T> {
iterator: IterableIterator<[string, string]>
}
编辑
我们已经看到
http://www.typescriptlang.org/docs/handbook/iterators-and-generators.html
Symbol
是 ES6
的新功能,因此您需要将编译器定位到它。
为此,指定 the compiler options 中的目标是 "es6"
.
Symbol
的定义可以在 the lib.es6.d.ts (while it's missing in the default lib.d.ts)
编辑
你可以自己填充那个部分,你只需要从 lib.es6.d.ts
文件中复制需要的部分并将其放入你自己的文件中并引用它。
我复制了您发布的代码所需的内容,它位于 this playground。
它可能比实际需要的更多,所以请尝试一下。
帮助我解决问题的是将以下设置添加到 tsconfig.json:
"lib": [
"es6",
"dom"
]
在那之后我又遇到了重复 Promise 声明的错误,但我只是删除了 polyfill 类型定义并且工作正常。 看起来 whatwg-fetch 并不真的需要 ES6 符号,代码可以使用 ES5 回退: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/11290