Using Namespaces for Cleaner Type Exports in TypeScript

Just a random question, but why didn't you use namespace for exporting type?

I am thinking about this approach for my own codebase to avoid the awkward MyData.MyData

Like:
// Option.ts
export type Option<A> = Some<A> | None;

export type Some<A> = { _tag: 'Some'; value: A };

export type None = { _tag: 'None' };

export namespace Option {
  export const some = <A>(value: A): Some<A> => ({ _tag: 'Some', value });
}

// A.ts
import { Option } from './Option';

export const A: Option<number> = Option.some(1);
Was this page helpful?