什么是“类型优先"?流架构? [英] What is the "types first" Flow architecture?

查看:57
本文介绍了什么是“类型优先"?流架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

博客文章描述了Flow的重新架构",称为类型优先".据我所知,唯一的描述是来自博客文章的引言:

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?

例如,这被允许吗?

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

在TypeScript中这是有问题的,因为如果不知道func的类型就无法解析myNumber的类型. Flow的类型优先"重新架构是否需要用户编写:

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.

推荐答案

听起来真的很浮华,也许是在幕后.但实际上,这很简单.在您的代码段中,您绝对是正确的,这几乎意味着全部.

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:

  • 性能改进,因为流程无需扫描所有依赖项即可对其进行健全性检查
  • 更可靠的代码,因为流在​​模块边界内运行,因此您不会遇到由深层嵌套的依赖关系引起的流错误.

自从类型首次正式发布以来,他们还发布了新的博客文章. https://medium.com/流类型/类型第一个可扩展的新体系结构,用于流3d8c7ba1d4eb

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

更新类型优先架构现已记录了.

这篇关于什么是“类型优先"?流架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆