Flow: Object type spread does not support generics (Did not expect BoundT)

Created on 17 Mar 2017  路  4Comments  路  Source: facebook/flow

Having Internal error: Failure(Did not expect BoundT) in this example

https://flowtype.org/try/#0C4TwDgpgBAsghiARhACgJwPYFsCWBnCAHgBUA+KAXinW3yLKgB8piBuAKHdEigGViAoikIBJAHIAaKAHkAqgyoAKRXABcUcQEpK5eElSZcBQnLKaO7AMYYAdnmBQwcYJYAW0xACsIl4CKxgADaUUIqaFKQA3gC+7FDxCYlJyVBWtvaOzm4e3r7qJKo5PsBSANKFXsWkinFQAGYArjaW6irqxNoRsAjINEZEpaTsneT8QiRSkQB0M8RSM1Ol0eRKTi7ulb7+QepwNiDmnNZ2DsAQ9rxnYCFr2ZvAivbO0F2RtfHHGW4+ANYAguoAORwQEhJ5nKZwDiJNAQYANNA2KCRKCIIGIUHRaFQaKaI7pBywvAhM4XK6KFFqKDAzGHIA

Intersection equivalent works fine https://flowtype.org/try/#0C4TwDgpgBAsghiARhACgJwPYFsCWBnCAHgBUA+KAXinW3yLKgB8piBuAKHdEigGViAoikIBJAHIAaKAHkAqgyoAKRXABcUcQEpK5eElSZcBQnLKaO7AMYYAdnmBQwcYJYAW0xACsIl4CKxgADaUUIqaFKQA3gC+7FDxCYlJyVBWtvaOzm4e3r7qJKo5PsBSANKFXsWkinFQAGYArjaW6irqxNoRsAjINEZEpaTsneT8QiRSxFAAZFCDIYpOLu6Vvv5B6nA2IOac1nYOwBD2vEdgIUvZq8CK9s7QXZG18fsZbj4A1gCC6gDkcL8QncjgA6OAcRJoCDABpoGxQSJQRB-RCA6IQqDRTR7dIOKF4EJHE5nRSItRQf5o3ZAA

Most helpful comment

Oh dear, sorry about that. <A,B>(A, B) => {...A, ...B} should definitely work, and should be the type of (a, b) => {...a, ...b}. Currently type spread does not support generics at all. Will need to figure out what to do for cases like <T>({...T, x: number}) => T though, since it's not immediately clear to me what even inhabits such a type. (maybe a => { var {x, ....b} = a; return b }?)

All 4 comments

This is what I'd love to write:
````js
const reducer = <
A: $Exact<>,
B: $Exact<
>,

(a: A, b: B): { ...A, ...B } => ({ ...a, ...b })
````

Oh dear, sorry about that. <A,B>(A, B) => {...A, ...B} should definitely work, and should be the type of (a, b) => {...a, ...b}. Currently type spread does not support generics at all. Will need to figure out what to do for cases like <T>({...T, x: number}) => T though, since it's not immediately clear to me what even inhabits such a type. (maybe a => { var {x, ....b} = a; return b }?)

I have a use case that _I think_ falls under this umbrella too which is almost a little bit like a type-aligned queue: the output to the next function is dependant on (as an extension of) the input type. I get the same error, and unfortunately I don't think b5f15fe will allow me to type check this yet either. I'm sorry I can't help more, but mostly commenting to highlight a use case I think would benefit greatly from type spread generics. 馃槃

https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVAXAngBwKZgBCAhgM4EC8YA3gD6phhRxwBcYAdgK4C2ARngBOAblS0AvqMy4CAdQCWGABYlBYKtQZg+xQe278hoyemz4wC5SQBe6mlp3X9vASNQnp5gBLEOAExghAB4AFXYScgA+O01GQS4OdgAKYnYQgEp1aIA3OHk-YykAYzgOUgxtMkowUPCqyJT2H39AwVDI9KbfAOCQ6Ipo4mLS8rAERRVdO3bGsGaetuoAOhWQgBowFaXLScFxDq6W3v7o2LBBPAwuQQ57RjiE5L40zIG7+8ZiJfiOJLOPxhbPhrLQAyp6MAAVhBYPE6VEH3EMLAJg8JTKFXGVmItioM1Sc26rSCy1WGy2Oxs+06hKObT6WXeFyuN3eD0SYCSzzAGUZ-3uXx+f1BAKByLBjnYAEYAAzi+5whEK5Go4YYsDlPA4KV2HTkYXsp51civU4i4DAMDEIpFPCkUjyDgAcytHCwykdLrgyiEYGUvm0S2YcA1SjgXBgfiYxHkMDASiEeBF6NIcECS3gTq5QZY8K0SPcedQKYqmpwACY7Fjdgbzo9OdzSUsInhySsdgAxFhwvnmy3W232z2u91KYfehNqf23Pg5kNwNSznRqUhhiNRqAxuOTpMfFNpvAZuBZpdTADUgeDecYBcV6BLYBKPBwcHIdiSUA2TtNnIAHj+oCSLN-yLC0NQwbpdCjJ8XzfKAEiKDB5FKYsRlLDAtQAZjsGDXzwJItGrVRkSInFUHSWsfiNGgthbNttgmGx6MpXQezefkwIHO0HWdEcPV4idfWnS8WDABdA2XMTFyWRxQ3DSNo1jeNE2TEYDyPE8ZJxMAL1PNRdLna8URBOF0DLKVvgSP5g3YSE7zLctLN+agbKheyMJwTCnOslhbLvIA

this does not fall with Internal error: Failure(Did not expect BoundT) in 45, 46, 47, 48 flow. Closing, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

damncabbage picture damncabbage  路  3Comments

philikon picture philikon  路  3Comments

john-gold picture john-gold  路  3Comments

Beingbook picture Beingbook  路  3Comments

cubika picture cubika  路  3Comments