Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.ts

Ask Question

I have created multiple interfaces and want to ship them all from a common index.ts file as shown below:

--pages
------index.interface.ts
--index.ts

Now In my index.ts I am exporting something like:

export { timeSlots } from './pages/index.interface';

whereas my index.interface.ts look like this:

export interface timeSlots {
  shivam: string;
  daniel: string;
  jonathan: string;

Now when I try to do so, it says me:

Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.ts(1205)

Not sure why this error shows up, can someone help?

You just need to use this syntax when re-exporting types:

export type { timeSlots } from './pages/index.interface';
//     ^^^^
// Use the "type" keyword

Or, if using a version of TypeScript >= 4.5, you can use the type modifier before each exported type identifier instead:

export { type timeSlots } from './pages/index.interface';
//       ^^^^
// Use the "type" keyword

The second approach allows you to mix type and value identifiers in a single export statement:

export { greet, type GreetOptions } from './greeting-module';

Where greeting-module.ts might look like this:

export type GreetOptions = {
  name: string;
export function greet(options: GreetOptions): void {
  console.log(`Hello ${options.name}!`);
                How would I do this in an AWS Code build environment? For example, I am getting this error from a library, and upon installation, it offers this typescript error.
– Luke
                Jan 9 at 18:37
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.