The following code throws an error. Can't figure out why.

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 Answers