How do I get exported types in a nice namespaces?

Viewed 35

Let's say I have these:

src/components/Thing/State.ts:

export type State = { name: string }

src/components/Thing/index.ts:

import { State } from './State'

const coolFunction = () => {}

export default {
  State,
  coolFunction,
}

because I want to say import Thing from '../Thing' and be able to reference Thing.State as well as Thing.coolFunction.

TypeScript is telling me that State is a type and not a value, but it's being used as a value. I get the concept of this error, but I don't know what to do about it. I want my related things namespaced, but this looks to be a hindrance.

What are my options here?

1 Answers

You can use variable/namespace merging :

const coolFunction = () => {}
const e = {
    coolFunction,
}
namespace e {
    export type State = import('./State').State;

}
export default e
Related