2015-12-01 7 views
6

既存の大きなプロジェクトにFlowtypeを追加することは可能ですか?既存のプロジェクトにフローを追加する

私は、単一の.jsファイルに/* @flow weak */を加え、次いでflow checkを実行し、それはそれらのいずれかが何であるかわかりませんので、それは機能のトンを強調していますが定義されたLIBSをグローバルに呼び出します。

[ignore] 
node_modules/ 
bower_components/ 
typings/ 

[include] 
twig/ 

[libs] 
bower_components/timezone-js/src/date.js 
bower_components/jquery/dist/jquery.js 
bower_components/jquery-migrate/jquery-migrate.js 
bower_components/jquery-ui/jquery-ui.js 
bower_components/jqueryui-touch-punch/jquery.ui.touch-punch.js 
bower_components/jquery-cookie/jquery.cookie.js 
bower_components/jquery.expander/jquery.expander.js 
bower_components/jquery.transit/jquery.transit.js 
www/js/select2.js 
bower_components/fancybox/source/jquery.fancybox.pack.js 
bower_components/lodash/lodash.js 
bower_components/underscore.string/lib/underscore.string.js 
bower_components/json2/json2.js 
bower_components/jquery-validation/dist/jquery.validate.js 
bower_components/jquery-file-upload/js/jquery.iframe-transport.js 
bower_components/jquery-file-upload/js/jquery.fileupload.js 
bower_components/DataTables/media/js/jquery.dataTables.js 
bower_components/jquery.taps/jquery.taps.js 
bower_components/file-saver.js/FileSaver.js 
bower_components/react/react.js 
bower_components/react/react-dom.js 
bower_components/react/react-dom-server.js 
node_modules/babel-core/external-helpers.js 
node_modules/babel-core/browser-polyfill.js 
... more libs ... 

[options] 
munge_underscores=true 

を私はflow checkを実行すると、今それだけでメモリ不足:だから私はこのように私.flowconfigファイルを更新しました。

だから、何ですか?私のプロジェクトは流れを使うには大きすぎますか?

+1

[この問題](https://github.com/facebook/flow/issues/869)が解決されるまで、IMOフローは実行可能ではありません。 – mpen

答えて

13

.flowconfigのパスは絶対パスでの正規表現です。したがって、このような何かnode_modulesの下にあるすべてのものを無視し、bower_componentsあなたが使用します。

[ignore] 
.*/node_modules/.* 
.*/bower_components/.* 

[libs]セクションでは、あなたの中にグローバルのタイプを定義しているdeclarations(インターフェイスファイル)を、流れるようにパスが含まれていますアプリ。あなたはすべてのインターフェイスのファイルを保存ディレクトリにこれをポイントすることができます:私たちはanyを使用しました

declare module "jQuery" { 
    declare function $(element: any): any; 
} 

注:たとえば

[libs] 
.*/lib/interfaces/.* 

、jQueryのために、あなたは次のように宣言を持つことができますこれは、この引数または戻り値の型チェックを無効にします。

ドキュメントのthird-party integrationsのセクションも参照してください。

+2

この回答は100%正しいです。また、Flowバージョン0.22では、 'node_modules'のすべてを無視する必要はありません。これは、Flowが非' @ flow'ファイルを解析しなくなり、過去にいくつかの問題が発生したためです。 0.22より、 'node_modules'の中で特定の問題ファイルを対象にする方が良いでしょう。見つかった、しかし '@ flow'以外のモジュールのデフォルトの動作は' any'です。この答えのような多くの定型文を保存します。 –

2

anyタイプの構文は多くの場合、declare function exports(args: any): any;は、モジュール内のすべてのプロパティを宣言するためにキャッチオールはありませんされるように、追跡には少しトリッキーだったので、マーティンの答えに拡大すること(例えば_.all、アンダースコアの場合は_.eachなど)。しかし、すべての場合には機能しません。ここで

が、私はその半作品を使用していたサンプル・インタフェース・ファイルの抜粋です:より詳細なインタフェースファイル例えば

declare module 'jquery' { 
    declare function exports(args: any): any; 
} 

declare module 'underscore' { 
    declare function exports(args: any): any; 
} 

// "declare function exports" doesn't seem to work in this case 
declare module 'react' { 
    declare var PropTypes: any; 
    declare var Component: any; 
    declare function createElement(args: any): any; 
    // ...and so on 
} 

、あなたは何facebook/flow's interface files look like on github見ることができます。

関連する問題