我正在尝试在Typescript环境中学习redux和immutable.js。使用我的Map的get方法时,我在选择器中收到翻译错误。
// ./selectors.ts
import { ErrorState } from './reducer';
import { ErrorReport } from './types';
// type ErrorState = { error: Map<string, Set<ErrorReport>> }
export const getReduxErrors = (
state: ErrorState,
search: string,
): Set<ErrorReport> | undefined => state.error.get(search);
我收到的翻译错误是:
Property '[Symbol.toStringTag]' is missing in type 'import("/mnt/9182c1a5-20ad-4aaf-b785-996d978bf303/DevProjects/nodejs/react_application/node_modules/immutable/dist/immutable-nonambient").Set<import("/mnt/9182c1a5-20ad-4aaf-b785-996d978bf303/DevProjects/nodejs/react_application/src/app/redux/features/error/types").ErrorReport>' but required in type 'Set<import("/mnt/9182c1a5-20ad-4aaf-b785-996d978bf303/DevProjects/nodejs/react_application/src/app/redux/features/error/types").ErrorReport>
[其他人以前都经历过吗?
我现在有一个类似的问题,就我而言,这是因为我在类型定义中使用了es6 Map,在实际实现中使用了不可变的Map。 ErrorState是否在您的情况下使用不可变的Map?如果您不从不可变的地图中导入地图,则不会出现“无法找到名称地图”错误,它只会默认为es6地图,并导致类似这样的错误