使用TypeScript约束名称

时间:2017-11-17 04:32:16

标签: reactjs typescript redux

我有这个州的财产:

export interface IStateProps
{
    location: LocationState;

    userId: number;
    counter: number;

    companyComponent: ICompanyComponent;
}

我希望reducer符合上面的名称:

const reducers: {[name in keyof IStateProps]} = {
    location        : locationReducer,
    counter         : counterReducer,
    userId          : userIdReducer,
    companyComponent: companyComponentReducer
};

const rootReducer = combineReducers(reducers);

const middlewares = applyMiddleware(middleware);
const composed    = compose(enhancer, middlewares);
const store       = createStore(rootReducer, composed);

// While redux is in version 3.7.2,
// overwrite redux/index.d.ts with this: https://raw.githubusercontent.com/reactjs/redux/index.d.ts
// const s = store.getState();
// so autocomplete or object destructuring would work 

然而,这导致getState()缺少计数器属性:

enter image description here

在维护对象的类型时,是否有任何方法可以从接口的属性名称约束对象的属性名称?并在编译期间进行检查。

上面一个不相关的问题,在哪里找到对齐属性的设置'使用WebStorm的接口声明的类型?那对应的TsLint是什么?

0 个答案:

没有答案