-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ignore type of overwritten object spread properties? #6800
Comments
type Optional = {name: ?string, foo: number}
type Required = {name: string, foo: number}
function normalize(input: Optional): Required {
return (({
...input,
name: input.name && 'unnamed',
}:any):Required)
}
|
@bhandarijiwan yes, that's a reasonable workaround, and I do things like that in all sorts of places... Using |
This is a duplicate of #6108. |
Duplicate of #6108 |
The following function is guaranteed to set the
name
property to a defined value, but Flow complains about the...input
spread because itsname
property is optional. Maybe the type ofname
from...input
should be ignored since it is overwritten by thename
in the object literal?Code Try flow link
Errors
Less performant workaround
The only type-safe workaround I can think of (using object rest spread or similar) incurs a performance penalty:
The text was updated successfully, but these errors were encountered: