gpt4 book ai didi

javascript - 是否可以将名为通配符的单行重新导出?

转载 作者:行者123 更新时间:2023-12-03 00:02:40 25 4
gpt4 key购买 nike

以下文件夹结构为例:

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;

但遗憾的是,无法在一条语句中重命名和包装导出。

关于javascript - 是否可以将名为通配符的单行重新导出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55105690/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com