在枚举中列出带有可选参数的对象上获取“元素隐式地具有'any'类型”

时间:2019-05-10 05:22:16

标签: typescript

以下代码引发错误。不知道为什么。

export enum ScreenSize {
  XS_MOBILE = 'XS_MOBILE',
  MOBILE = 'MOBILE',
  TABLET_PORTRAIT = 'TABLET_PORTRAIT',
  DESKTOP = 'DESKTOP',
  TABLET_LANDSCAPE = 'TABLET_LANDSCAPE',
  SS_DESKTOP = 'SS_DESKTOP',
}

export type SizingMap = { [key in ScreenSize]?: number };

const map:SizingMap = { DESKTOP: 3 }

const size = 'DESKTOP';

// ERROR: Element implicitly has an 'any' type because type 'SizingMap' has no index signature.ts(7017)
if(map[size]) { .... }

0 个答案:

没有答案