Flow: Feature request: I way to specify a partial version of an object type

Created on 5 Jun 2015  路  4Comments  路  Source: facebook/flow

Say I have a type:

type State = {
  foo: string,
  bar: number
};

It would be really useful to be able to specify an update version of the type in which all the fields are optional.

type UpdateState = {
  foo?: string,
  bar?: number
}

For example in React the argument of setType should be an all optional version of the state type for the component.

Maybe syntax like function setState(state: #State)?

Does this sound feasible and/or a good idea? Or am I missing the obvious way to do this sort of thing already?

Most helpful comment

What you are describing is implemented, but not documented or technically a "public" API. It's called $Shape and it's already used to type React's setState function. See the definition in lib/react.js.

You can find more about this and other types in this awesome blog post.

All 4 comments

What you are describing is implemented, but not documented or technically a "public" API. It's called $Shape and it's already used to type React's setState function. See the definition in lib/react.js.

You can find more about this and other types in this awesome blog post.

Thanks!

@samwgoldman how am I supposed to get knowledge about this $Shape feature?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

philikon picture philikon  路  3Comments

mjj2000 picture mjj2000  路  3Comments

ctrlplusb picture ctrlplusb  路  3Comments

glenjamin picture glenjamin  路  3Comments