I’m getting the typescript error Property 'UPDATE_COLUMNS' does not exist on type 'DimensionAction'.ts(2339) Even though you can see it is defined right above.
I’m using VSCode. I’m wondering if this is a bug with my IDE. I’ve run yarn lint and the syntax everywhere else in my code is totally fine.
export enum DimensionAction {
UPDATE_ROWS = 'update_rows',
UPDATE_COLUMNS = 'update_columns',
}
const dimensionReducer = (state: Dimension, action: DimensionAction): void => {
switch (action) {
case action.UPDATE_COLUMNS:
break
case action.UPDATE_ROWS:
break
default:
throw Error('Must pass action')
}
}
Why isn’t this code valid Typescript?
>Solution :
You should access the specific enumeration on the enum type itself.
case DimensionAction.UPDATE_COLUMNS:
Also, there is no need for a separate case for UPDATE_ROWS; it can just be handled in default. action: DimensionAction does not allow for action to be null, undefined, or anything other than one of the DimensionAction enum values.
