如何将node-fetch包导入到我使用typescript. 我尝试了很多方法......现在我正在:
const fetch = (...args) =>
import("node-fetch").then(({ default: fetch }) => fetch(...args));
Run Code Online (Sandbox Code Playgroud)
但我有两个错误:
Cannot redeclare block-scoped variable 'fetch'.
Run Code Online (Sandbox Code Playgroud)
和
A spread argument must either have a tuple type or be passed to a rest parameter.
Run Code Online (Sandbox Code Playgroud)
当我更改const fetch =为任何其他名称时,例如const fetchIt =它修复了第一个错误,但是......我真的必须更改它吗?如何node-fetch以正常方式导入包,我可以使用fetch()方法?在 React 中我只是做
import fetch from 'node-fetch';
Run Code Online (Sandbox Code Playgroud)
一切都很好......为什么在node项目中如此困难?
我在我的项目中使用 ag-grid 并且我在应用表状态时遇到问题。这是我的onGridReady函数代码片段:
this.gridApi = params.api;
this.gridColumnApi = params.columnApi;
if (!window.colState) {
console.log("no columns state to restore by, you must save state first");
} else {
this.gridColumnApi.applyColumnState({
state: window.colState,
applyOrder: true,
});
console.log("column state restored");
}
Run Code Online (Sandbox Code Playgroud)
它当然取自 ag-grid。就在它下面,我拥有
this.gridColumnApi.getAllColumns()
和this.gridColumnApi.autoSizeColumns()
运行良好的功能。
问题是this.gridColumnApi.applyColumnState给了我这个错误。
TypeError: _this.gridColumnApi.applyColumnState is not a function
Run Code Online (Sandbox Code Playgroud)
我不明白为什么调用的其他函数this.gridColumnApi有效但applyColumnState没有。有什么建议?
@edit 我什至尝试过这个:
componentWillUnmount() {
window.colState = this.props.gridColumnApi.getColumnState();
console.log("column state saved");
if (this.props.gridColumnApi.applyColumnState) {
devLog("IT IS HERE");
} else {
devLog("its not");
} …Run Code Online (Sandbox Code Playgroud)