Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
189 views
in Technique[技术] by (71.8m points)

javascript - What is the "types first" Flow architecture?

A blog post by the Flow team describes a "re-architecture" of Flow called "types-first". As far as I can tell, the only description is in this quote from the blog post:

"...it exploits full type annotations at file boundaries to perform better (more parallelizable and less redundant) separate compilation."

Is there more detail about this anywhere? Specifically, I'm wondering what these full annotations are: what are the new restrictions on source code and declaration files?

For example, is this allowed?

import { func } from "./other-module";
export const myNumber = func(num1, num2);

It's problematic in TypeScript, since the type of myNumber is impossible to resolve without knowing the type of func. Will the "types-first" re-architecture of Flow require users to write:

import { func } from "./other-module";
export const myNumber: number = func(num1, num2);

This is just one specific question I have. What I'm looking for is a little bit more information and a link to a document explaining all the known implications of the re-architecture.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It sounds really flashy and maybe it is under the hood. But in reality it's quite simple. In your code snippet you're absolutely correct, it pretty much means just that.

You must have an explicitly defined type before you export

Though not necessarily right before you export. The following works too.

const TestComponent = (): React.Node => {};

export default TestComponent;

It adds a little more overhead, but the benefits are:

  • improvements in performance because flow doesn't need to scan all dependencies before it can give you soundness checks
  • More reliable code because flow runs within module boundaries so you don't get flow errors that are caused by deeply nested dependencies.

They've also released a new blog post that goes into this further since types first have now been released officially. https://medium.com/flow-type/types-first-a-scalable-new-architecture-for-flow-3d8c7ba1d4eb

UPDATE The types-first architecture is now documented.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...