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

70 views Asked by At

I dont know what is the exact differences.

I want to know what is the differences

1

There are 1 answers

1
jeremy-denis On

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

sample from doc

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

=> failed because foo can only have a foo property. Bar is unauthorized

but if you do the following it will work

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