Gib*_*boK 28 javascript flowtype
我遇到了以下用js FlowType编写的代码(我有兴趣知道在FlowType的上下文中+的值不是普通的JS).
您能否+在下面的代码中解释一下该符号在该物业前的含义:
export type User = {
+name: string,
+surname: string,
+personId: PourceId,
}
Run Code Online (Sandbox Code Playgroud)
我在文档中找不到任何参考,也欢迎任何链接.
' + '符号表示该属性是只读的,
' - '表示该属性是只写的,
如果没有任何'+'或' - '符号,则表示该属性具有读/写访问权限.
它可以在定义接口属性或类型属性时使用.
文档可以在以下链接中找到:https:
//flow.org/en/docs/types/interfaces/#toc-interface-property-variance-read-only-and-write-only
经过一些额外的研究,我发现+/-表明属性的协变或逆变。
interface MyInterface {
+covariant: number; // read-only
-contravariant: number; // write-only
}
Run Code Online (Sandbox Code Playgroud)
关于方差的有趣文章:
https://flow.org/en/docs/lang/variance/
https://flow.org/en/docs/types/interfaces/#toc-interface-property-variance-read-only-and-write-only
| 归档时间: |
|
| 查看次数: |
5313 次 |
| 最近记录: |