Export all interfaces/types from one file in TypeScript project


The direct interface to my library is captured by


which is currently auto-generated from


in my package.json file for my project, typings/types properties point to this index.d.ts file, which is to my understanding, how it should be. All good so far.

However, there are some more types that I would like to export from index.d.ts that are not currently expressed in index.d.ts.

For example I have some manually created types in


and I want these to be expressed in index.d.ts.

The only way I think that might work, is to import the foo.d.ts/bar.d.ts types into index.d.ts and then in turn export them from that file.

However, I am having trouble with that!

Here is what I tried:

// index.ts

import {IBar} from '../bar.d.ts'
import {IFoo} from '../foo.d.ts'

// ... do some stuff with index.ts yadda yadda

export type IBar = IBar; // doesn't seem to work
export interface IFoo = IFoo; // doesn't seem to work

is this possible? How do I do this?


You can export them directly if you don’t need to use them.

export * from '../foo/bar';

Or if you need to export only some of them you can use.

export { IFoo, IBar} from '../foo/bar';

Or if you want to rename them during export you can do:

export { IFoo as IOther, IBar as Dogs } from '../foo/bar';

You can read more about them in the MDN documentation here.

Answered By – toskv

Answer Checked By – Dawn Plyler (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.