別のモジュールからインポートされた型定義がある場合、どのように再エクスポートしますか?別のファイルからインポートされたフロータイプ定義をどのようにエクスポートしますか?
/**
* @flow
*/
import type * as ExampleType from './ExampleType';
...
// What is the syntax for exporting the type?
// export { ExampleType };
別のモジュールからインポートされた型定義がある場合、どのように再エクスポートしますか?別のファイルからインポートされたフロータイプ定義をどのようにエクスポートしますか?
/**
* @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;
を書くときは、明示的number
のエイリアスタイプの別名MyTypeAlias
を作成しています。あなたは
import type { YourTypeAlias } from './YourModule';
を書くとき、あなたは暗黙的にYourModule.js
のYourTypeAlias
輸出のエイリアスタイプの別名YourTypeAlias
を作成しています。
しかし、どのようにして簡単にすべての型を1行に再エクスポートできますか? –
この記事によると、 'export type {ExampleType}'はサポートされている構文ではありません。 https://flowtype.org/blog/2015/02/18/Import-Types.html投稿の情報が最新ではありませんか?この構文はどこに文書化されていますか? https://flowtype.org/docs/modules.htmlにも記載されていません。 – Gajus
FYI、 'babel-plugin-transform-flow-comments'に関するBabelのhttps://github.com/babel/babel/issues/5538に関連する問題を記入しました。 – Gajus
これは
export type { MyType } from './types';
編集取り組んでいる:は、受け入れられた答えは古いものと私の最後に警告を投げているreact-native-tab-view
で行われている方法から、この構文を取得します。ビューの量を考えると、フロー0.10+と互換性のある最新の回答があります。
MyTypes.js:
export type UserID = number;
export type User = {
id: UserID,
firstName: string,
lastName: string
};
user.jsの:
import type {UserID, User} from "MyTypes";
function getUserID(user: User): UserID {
return user.id;
}
代わりの './ExampleType' からExampleTypeとして 'インポートタイプ*書き込み;' を 書くことができます 'import type ExampleType from './ ExampleType ';' –