typescript tip: step is any type. This is too bad!
How do I optimize?
export function foo (isActive:boolean) {
let step
if (isActive) {
step = [
'1ICK750', '2IYE230', '3CI0320', '3CI0720', '4PGC938'
] as const
} else {
step = [
'are', 'by', 'sea', 'seashells', 'she', 'shore', 'the', 'zoo'
] as const
}
// ...more
// typescript tip: step is any type.This is too bad!
return step
}
you can make the step like this
let step: string[] = []
now your return type will also be a string of array.
Define it using the conditional operator instead.
const step = isActive
? ['1ICK750', '2IYE230', '3CI0320', '3CI0720', '4PGC938'] as const
: ['are', 'by', 'sea', 'seashells', 'she', 'shore', 'the', 'zoo'] as const;