This used to work in v0.39:
function hasId(obj: { +id?: number }): void {
}
type T = {|
name: string,
|}
const obj: T = { name: 'ok' }
hasId(obj)
Now breaks since v0.40:
https://flowtype.org/try/#0PQKgBAAgZgNg9gdzCYAoVUCuA7AxgFwEs5swALAQwGcBJAEwAo4AjAKwC4wBvMAakLoB+TtkwBbZgFMATmAC+ASk4A3OAO6o56fAE8ADpLAAVMAF5uAH1Rgw2CmMmcq+aYWwBzADSoLW1LhJnMBYOYzNuW3tHMAByOABrGPl0SlpGEIUgA
I'm not sure there's a bug here. Flow clearly know that id will never exist on a T. So I think Flow is working as expected.
Well my function takes an object that may have an id, it's not required. Because I'm only reading it, I don't see why flow would not allow me to pass an object that doesn't have one, the function would just read undefined and work as expected. There was no error in v0.39 and I don't see anything in the changelog related to this.
Most helpful comment
Well my function takes an object that may have an
id, it's not required. Because I'm only reading it, I don't see why flow would not allow me to pass an object that doesn't have one, the function would just readundefinedand work as expected. There was no error inv0.39and I don't see anything in the changelog related to this.