2

In file defs.ts I define an enum and export it...

enum MyState {
    state1 = 'state1'
    state2 = 'state2'
... state5 = 'state5'
}

this gets exported to index.tsx of a Component and exported from there

export {
    MyState,
    ... 
}

It then gets imported into a file in another Component

import { MyState } from "../Component1"

const filterMap: { [key: string]: { title: string; filter: object } } = {
  s1: { title: 's1', filter: { state: MyState.state1 } },
  s2: { title: 's2', filter: { state: MyState.state2 } },
  s2: { title: 's3', filter: { state_ne: [MyState.state3 ] } },
}

However on being run, an error gets generated

Uncaught TypeError: Cannot read properties of undefined (reading 'MyState')

WTF is going on?

1 Answer 1

1

This works for me

defs.ts

export enum MyState {
    state1 = 'state1',
    state2 = 'state2',
    state5 = 'state5',
}

Component2.tsx

import { MyState } from './defs'
const filterMap: { [key: string]: { title: string; filter: object } } = {
  s1: { title: 's1', filter: { state: MyState.state1 } },
  s2: { title: 's2', filter: { state: MyState.state2 } },
  s2: { title: 's3', filter: { state_ne: [MyState.state5 ] } },
}

If you need to export it from an intermediary you would do something like this.

Component1.tsx

export * from './defs'

I

Sign up to request clarification or add additional context in comments.

1 Comment

Yep it appears adding an intermediary layer upsets things - thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.