gpt4 book ai didi

javascript - 如何导出从另一个文件导入的流类型定义?

转载 作者:行者123 更新时间:2023-12-03 13:14:20 27 4
gpt4 key购买 nike

给定从另一个模块导入的类型定义,如何重新导出它?

/**
* @flow
*/

import type * as ExampleType from './ExampleType';

...

// What is the syntax for exporting the type?
// export { ExampleType };

最佳答案

这个问题的最简单形式是“如何导出类型别名?”简单的答案是“使用 export type!”

对于您的示例,您可以编写

/**
* @flow
*/

import type * as ExampleType from './ExampleType';
export type { ExampleType };

您可能会问“为什么 ExampleType 是类型别名?”好吧,当你写
type MyTypeAlias = number;

您正在显式创建类型别名 MyTypeAlias哪个别名 number .当你写
import type { YourTypeAlias } from './YourModule';

您正在隐式创建类型别名 YourTypeAlias别名 YourTypeAlias YourModule.js 的导出.

关于javascript - 如何导出从另一个文件导入的流类型定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32602957/

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