我有一个模块可以chalk
根据我的特定需求修补颜色。这是代码:
import { ChalkStyleElement, ChalkStyleMap, styles } from 'chalk';
import escape from './escape';
/**
* Decorate ASCII-colors with shell-specific escapes
*/
let PatchedChalkStyleMap: ChalkStyleMap;
Object.keys(styles).forEach((style: string) => {
PatchedChalkStyleMap[style] = {
close: escape(styles[style].close),
open: escape(styles[style].open),
reset: escape(styles[style].reset),
};
});
上面我只是浏览了所有chalk
样式并用我的特殊escape
功能修补它们。但是,这不会编译。我收到这些错误:
src/colors.ts(10,3): error TS7017: Element implicitly has an 'any' type because type 'ChalkStyleMap' has no index signature.
src/colors.ts(11,16): error TS7017: Element implicitly has an 'any' type because type 'ChalkStyleMap' has no index signature.
src/colors.ts(12,15): error TS7017: Element implicitly has an 'any' type because type 'ChalkStyleMap' has no index signature.
src/colors.ts(13,16): error TS7017: Element implicitly has an 'any' type because type 'ChalkStyleMap' has no index signature
另外,我应该说我"noImplicitAny"
的tsconfig.json
.
我怎样才能在这里正确地描述类型,而不是隐含的any
?