Is it possible to export * as foo in typescript

TypeScript 3.8 or Later

See https://stackoverflow.com/a/59712387/1108891 for details.

Before TypeScript 3.7 or Earlier

Is it possible to export * as foo in typescript

Nope. You can, however, use a two step process:

src/core/index.ts

import * as Foo from "./foo";
import * as Bar from "./bar";

export {
    Foo,
    Bar,
}

src/index.ts

import { Foo, Bar } from "./core";

function FooBarBazBop() {
    Foo.Baz;
    Foo.Bop;
    Bar.Baz;
    Bar.Bop;
}

src/core/foo/index.ts and src/core/bar/index.ts

export * from "./baz";
export * from "./bop";

src/core/foo/baz.ts and src/core/bar/baz.ts

export class Baz {

}

src/core/foo/bop.ts and src/core/bar/bop.ts

export class Bop {

}

See also: https://www.typescriptlang.org/docs/handbook/modules.html

Leave a Comment