Dynamic property names in a stream type

I am slowly and confidently running flowType in my code, but I am struggling with one concept.

How to specify the type of unknown, dynamically named properties of an object?

For example, my custom object may have an object containing organizations with unique keys.

How would this be determined?

export type User = ?{ currentOrg: string, displayName?: string, email: string, emailVerified: boolean, newAccount: boolean, organisations?: { UNKNOWNKEY?: string { orgData1: string, orgData2: string, } }, uid: string, photoUrl?: string, }; 

It would be very helpful to help with this. Thanks!

+13
javascript syntax flowtype
source share
1 answer

Flow has a specific syntax for objects that behave like maps:

 { [key: K]: V } 

where K is the type of keys and V is the type of values.

Your complete example would look like this:

 export type User = { currentOrg: string, displayName?: string, email: string, emailVerified: boolean, newAccount: boolean, organisations?: { [key: string]: string }, uid: string, photoUrl?: string, }; 
+16
source share

All Articles