简体   繁体   English

流动型。 {} 和 {||} 类型有什么区别

[英]Flow type. What is the difference between type {} & {||}

I dont know what is the exact differences.我不知道确切的区别是什么。

I want to know what is the differences我想知道有什么区别

According to doc https://flow.org/en/docs/types/objects/#toc-exact-object-types {||} is a way to check for “exact” object types => no extra properties will be authorized with type with {||} syntax根据文档https://flow.org/en/docs/types/objects/#toc-exact-object-types {||}是一种检查“精确” object 类型的方法 => 不会授权额外的属性带有{||}语法的类型

sample from doc文件样本

// @flow
var foo: {| foo: string |} = { foo: "Hello", bar: "World!" }; // Error!

=> failed because foo can only have a foo property. => 失败,因为 foo 只能有一个 foo 属性。 Bar is unauthorized酒吧未经授权

but if you do the following it will work但如果您执行以下操作,它将起作用

var foo: { foo: string } = { foo: "Hello", bar: "World!" }; // Work

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 流类型中的(a:?string)和(a?:string)有什么区别? - What is the difference between (a: ?string) and (a?: string) in flow type? 对象类型中缺少 ClassName 道具。 流和 CSS 模块 - ClassName props is missing in object type. Flow and CSS Modules 流类型错误:未知类型的属性。 该类型与数组类型不兼容 - Flow Type error: property of unknown type. This type is incompatible with array type 流类型:“可选功能参数”和“可能的类型”之间的区别 - Flow Type: difference between “optional function parameters” and “maybe types” $ .ajax与type:post和$ .post之间有什么区别? - What is the difference between $.ajax with type: post and $.post Strapi 内容类型和组件之间有什么区别? - what is difference between strapi content type and component? 在Typescript中,类型和接口有什么区别? - In Typescript, what is the difference between type and interface? 对象和对象类型有什么区别 - What is the difference between Object and object type *和*流量之间有什么区别? - what is the difference between any and * in flow? JavaScript正则表达式中type = number和type = text有什么区别? - What is difference between type=number and type=text in JavaScript regex?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM