【发布时间】:2021-12-20 20:56:38
【问题描述】:
我有一个界面
interface IApplicationState {
config: IConfig;
lang: ILang;
//many others
}
目前在许多地方使用,例如在 connect from react-redux 的类中,或在 reducers 方法中,例如:
const setLangReducer = (state: IApplicationState , { lang }: { lang: LangType }): IApplicationState => ({
...state,
lang: {
currentLang: lang
}
});
我想在根级别添加一些文件,并将所有现有的作为新属性的子级向下移动,例如:
interface IApplicationState {
generalConfigs: {
config: IConfig;
lang: ILang;
};
externalConfig: {
domain: string;
}
}
如果我手动进行更改,我必须将 config 和 lang 的所有引用从 root 修复为 generalConfigs.config 和 generalConfigs.lang
也许有一些自动选项可以通过更改接口结构来更改所有引用?
【问题讨论】:
-
你可以写一个codemod来做到这一点:toptal.com/javascript/write-code-to-rewrite-your-code
标签: javascript typescript visual-studio-code