I've come across some samples for a React DND and within one of them was the following code:
export type Author = {|
id: string,
name: string,
avatarUrl: string,
url: string,
|}
There are several export types like this with the double pipe {|...|}
in object brackets, and, despite my research, I can't find anything that explains what it does. I assume it's due to there being multiple Authors that are combined into the final object (re: the following code) and the double-pipes prevent some sort of conflict.
const princess: Author = {
id: '4',
name: 'Princess bubblegum',
url: '',
avatarUrl: '',
};
export const authors: Author[] = [
jake, BMO, finn, princess,
];
This is a flowtype exact object type annotation.
https://flow.org/en/docs/types/objects/#toc-exact-object-types
Sometimes it is useful to disable this behavior and only allow a specific set of properties. For this, Flow supports “exact” object types.
Basically, it will not allow any props outside of the defined ones and should complain if you add, say... age: 40
to an Author
object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With