0

Take following folder structure as an example:

example.ts
outer/
|--- inner/
   |--- index.ts
   |--- file1.ts
   |--- file2.ts
|--- index.ts

Content of file1.ts

export class FileOneClass{/**/}
export interface IFileOneInterface{/**/}

Content of file2.ts:

export class FileTwoClass{/**/}
export interface IFileTwoInterface{/**/}

Content of outer/inner/index.ts:

export { FileOneClass, IFileOneInterface } from "./file1.ts"
export { FileTwoClass, IFileTwoInterface } from "./file2.ts"

Content of outer/index.ts:

import * as InnerImport from "./inner";
export const Inner = InnerImport;

Content of example.ts:

import { Inner } from "./outer"

    function exampleUsage(){
      console.log(Inner.FileOneClass)
      console.log(Inner.FileOneInterface)

      console.log(Inner.FileTwoClass)
      console.log(Inner.FileTwoInterface)
    }

My Question:

Is there a way to write the export statement in outer/index.ts into one single line?

// Ugly:
import * as InnerImport from "./inner";
export const Inner = InnerImport;

// Desired is something like this:
export * as Inner from "./inner"; // This line leads to a error!
ysfaran
  • 5,189
  • 3
  • 21
  • 51

1 Answers1

1

Well, sure (just kidding):

import * as InnerImport from "./inner"; export const Inner = InnerImport;

But there is unfortunately no way to rename and wrap the exports in one statement.

Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151
  • 2
    Starting with typescript 3.8 syntax like [`export * as ns`](https://devblogs.microsoft.com/typescript/announcing-typescript-3-8-beta/#export-star-as-namespace-syntax) is possible! – ysfaran Feb 03 '20 at 07:54