gpt4 book ai didi

javascript - 具有更深路径的库的流 libdef

转载 作者:行者123 更新时间:2023-11-30 14:29:59 24 4
gpt4 key购买 nike

我正在测试用于输入 JavaScript 的 Flow,我想为内部库创建一个 libdef。它是这样导入的:

import withValidation from 'internally-shared-libs/decorators/withValidation';

The documentation并没有真正解决如何为像这样的深层路径创建库定义 - 只有顶级路径。

我应该把 libdef 文件放在哪里?我怎么调用它?它看起来如何(当然忽略 libdef 的实际实现)?

提前感谢您对此提供的任何帮助!

最佳答案

您可以在一个 libdef 中有多个 declare module。您可以使用深层路径作为模块名称。这个 libdef 文件在哪里并不重要,只要它包含在 .flowconfig[libs] 部分中即可。

这是一个示例,其中 internally-shared-libs 具有导出以及具有导出的更深路径:

自由定义:

// @flow

declare module 'internally-shared-libs' {
declare export function hello(): string;
declare export function bye(): string;
}

declare module 'internally-shared-libs/decorators/withValidation' {
// You will obviously want to improve these types
declare type Input = any;
declare type Output = any;
declare export default function withValidation(input: Input): Output;
}

用法:

// @flow

import { hello, bye } from 'internally-shared-libs';
import withValidation from 'internally-shared-libs/decorators/withValidation';

关于javascript - 具有更深路径的库的流 libdef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51357664/

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