Is it possible to export * as foo in typescript

Solution 1:

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

Solution 2:

Since TypeScript 3.8 has been released you are able to add alias for your exports.

Example:

export * as utilities from "./utilities.js";

Ref: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html