gpt4 book ai didi

flowtype - 如何使用 CommonJS 导出流接口(interface)?

转载 作者:行者123 更新时间:2023-12-04 20:28:16 26 4
gpt4 key购买 nike

我不确定我的构建是否良好,但在我的 package.json , 我有

"scripts": {
"build": "flow-remove-types src/ -d build/",

我有一个 types/sentence.js , 其中有:
// @flow

type SentenceObject = {
foo: number,
bar: boolean,
baz: string,
};

module.exports = {
SentenceObject
};

在我的库文件中,我有:
const { SentenceObject } = require('../interfaces/sentence');

问题,当我做 yarn build是:
src/interfaces/sentence.js
↳ Syntax Error: Unexpected token, expected = (3:27)
2: export type SentenceObject {

我做错了什么?

最佳答案

好像有no CommonJS style for require flow types .相反,您可以使用 export/import as suggested in docs .所以在你的情况下,它可能是这样的:
types/sentence.js :

// @flow
export type SentenceObject = {
foo: number,
bar: boolean,
baz: string,
};

注意 export关键词。

在您的库文件中,您可以使用 import type {...} from '' :
import type { SentenceObject } from '../interfaces/sentence';

关于flowtype - 如何使用 CommonJS 导出流接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53046735/

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