【发布时间】:2021-12-08 13:38:01
【问题描述】:
有以下原始代码,它是一个基于toCheck的值的函数正在构建一个css类:
const computeSomething = (toCheck: string) => {
return clsx('flex', {
'flex-start': toCheck === 'FIRST',
'flex-end': toCheck === 'LAST'
});
}
要求将enum 用于toCheck,尝试了一些但可能是错误的:
export enum toCheck {
FIRST = 'FIRST',
LAST = 'LAST'
}
const computeSomething = (toCheck: string) => {
return clsx('flex', {
'flex-start': toCheck.FIRST,
'flex-end': toCheck.LAST
});
}
错误提示:
“字符串”类型上不存在属性“FIRST”。
有什么想法吗?
【问题讨论】:
-
你甚至没有使用参数
toCheck: string
标签: javascript reactjs typescript enums react-typescript