我试图通过以下方式访问导入对象上的属性:
import * as reducers from './reducers';
const reducer = reducers[rule.reducer.name](rule.reducer.args);
我的异径管在其他地方的定义如下:
export const sum = (property: string) => (pageViews: IPageView[]): number =>
pageViews.reduce((acc, pageView) => Number(acc + pageView[property]), 0);
我还具有以下类型定义:
export interface IPageView {
features: object;
}
interface IConditionQuery {
property: string;
value?: any;
}
interface IConditionRule {
reducer?: {
name: string;
args?: any;
};
matcher?: {
name: string;
args: any;
};
}
export interface ICondition {
filter: {
any: boolean;
queries: IConditionQuery[];
};
rules: IConditionRule[];
}
所以我了解(我认为)我可能正在访问一个reducer
的问题,因为我正在传递一个string
,所以我不确定该怎么做解决这个问题。
我尝试过的工作是对各种形式的enums
进行硬编码,但没有运气。
编辑: 完整的错误消息
semantic error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'typeof import("/Users/dennisyurkevich/dev/edkt/engine/src/reducers")'.
No index signature with a parameter of type 'string' was found on type 'typeof import("/Users/dennisyurkevich/dev/edkt/engine/src/reducers")'.