是一条名为通配符重新出口的一条线



以以下文件夹结构为例:

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

file1.ts

的内容
export class FileOneClass{/**/}
export interface IFileOneInterface{/**/}

file2.ts的内容:

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

outer/inner/index.ts的内容:

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

outer/index.ts的内容:

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

example.ts的内容:

import { Inner } from "./outer"
    function exampleUsage(){
      console.log(Inner.FileOneClass)
      console.log(Inner.FileOneInterface)
      console.log(Inner.FileTwoClass)
      console.log(Inner.FileTwoInterface)
    }

我的问题:

有没有办法将outer/index.ts中的导出语句写入一行?

// 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!

好吧,确定(只是开玩笑):

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

但是不幸的是,没有办法将出口重命名和包装在一个语句中。

最新更新