Flow: Can I override types?

Created on 17 Mar 2017  路  1Comment  路  Source: facebook/flow

I quite often send data over a REST api which causes e.g. Date objects to be converted to strings. Currently I handle this like so:

type A = { many more properties }  
type A_server = { time: Date } & A;  
type A_client = { time: string } & A;

Is there a way to override types?

Most helpful comment

You could always do: {time: Date | string};

I don't think you can override types. That wouldn't work with the model where any type can depend on any type anywhere in the file.


PS. Also you should update to the newly release object type spread instead of using &.

>All comments

You could always do: {time: Date | string};

I don't think you can override types. That wouldn't work with the model where any type can depend on any type anywhere in the file.


PS. Also you should update to the newly release object type spread instead of using &.

Was this page helpful?
0 / 5 - 0 ratings