Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to re-export all types from module?

Tags:

typescript

I want to re-export all types in a module. Is there a way to achieve this?

I did try:

export type * from 'react-router-dom';

But it doesn't work:

Only named exports may use 'export type'. ts(1383)

like image 416
Ramon Balthazar Avatar asked Mar 10 '26 08:03

Ramon Balthazar


2 Answers

Typescript 5.0 now has support for this:

export type * from "external-module"

//OR

export type * as ns from "external-module".

Update typescript and you’ll be able to!

like image 145
Justin Dalrymple Avatar answered Mar 14 '26 22:03

Justin Dalrymple


First, you need to import the type as Types then export it like this way.

// your-module
import type * as Types from "external-module";
export { Types };

// Usage by the end user
import { Types } from "your-module";
let a:Types.Class;

hope it's helpful.

like image 33
Ahmed Hall Avatar answered Mar 14 '26 23:03

Ahmed Hall



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!