以以下文件夹结构为例:
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
中的export语句写到一行?
// 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!
答案 0 :(得分:1)
好吧,确定(开个玩笑):
import * as InnerImport from "./inner"; export const Inner = InnerImport;
但是不幸的是,没有办法在一条语句中重命名出口并将其包装。