我试图弄清楚为什么getLabelForType
有效,但getOtherLableForType
输入失败:
export const things = {
THING1: 'THING1',
THING2: 'THING2',
}
export type Thing = $Keys<typeof things>
type Empty = 'empty type' & 'nothing there'
export default function unexpectedCase(impossible: Empty): void {
throw new Error(`Unexpected case ${impossible}`)
}
export function getLabelForType(thing: Thing): string {
switch (thing) {
case 'THING1':
return 'Thing 1'
case 'THING2':
return 'Thing 2'
default:
unexpectedCase(thing)
return ''
}
}
export function getOtherLabelForType(thing: Thing): string {
(things.THING1: Thing)
switch (thing) {
case things.THING1:
return 'Thing 1'
case things.THING1:
return 'Thing 2'
default:
unexpectedCase(thing)
return ''
}
}