Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Property does not exist on type (2339)

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.

Code bug

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading