🔎 Search Terms
function union infer
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about Structural vs Instantiation-Based Inference
⏯ Playground Link
https://www.typescriptlang.org/play/?jsx=0#code/C4TwDgpgBAYgrgOwMbAJYHsEEMA2BhdAWzEwgWAB4AVAPigF4oAKMAJ3TAGcAuKKgSgZ1OwVqgQBzANwAoGUkwiowCEsbUaLdl14BvKADdccVbyoBtALoAaKJwg4IKCABMzUAL6D6dXTKgBUAoISrpGOCactvaOzi4eDFBsHJyygVCsEMBwrAhQAAYqIrwAJGHGqh7RDk4qblBlMbWuHvmyHrLBSgTEpOQAClicIgAW7HASI4kaTArEvPDIaJi4PSQIZJS0-AuIKBjY+ETrmxpCQcey8orAUGt9wACCE4Sb07Szx7tLB6vHDxodrA9stDvcNuQzgAyKD6VD1BBwQgAIwgrE85wA8siAFa1AB0Q04qAkCE+xFscPqAEYAAyefhXLq3LCJcGbQbDYBjdATEZMIrARnXEK3ZFs-4Qp4vTYC1RCqRAA
💻 Code
typeFunctionalComponent<T>=(props: T)=>string;consttest=<T>(props: {values: T[],selected: T})=>{const{values, selected}=props;return`test: ${values}, selected: ${selected}`;};constComponentPassthrough=<T>(comp: FunctionalComponent<T>): FunctionalComponent<T>=>comp;constComponentAugment=<T>(comp: FunctionalComponent<T>): FunctionalComponent<T>&{id: number}=>Object.assign(comp,{id: 10});consta=ComponentPassthrough(test);constb=ComponentAugment(test);🙁 Actual behavior
Typescript cannot infer/passthrough the type parameter in ComponentAugment
🙂 Expected behavior
It should resolve ComponentAugment the same way it does with ComponentPassthrough, but with the added id property in this case. The expected type of b in this example should be:
(<T>(props: {values: T[];selected: T;})=>string)&{id: number}Additional information about the issue
No response
🔎 Search Terms
function union infer
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?jsx=0#code/C4TwDgpgBAYgrgOwMbAJYHsEEMA2BhdAWzEwgWAB4AVAPigF4oAKMAJ3TAGcAuKKgSgZ1OwVqgQBzANwAoGUkwiowCEsbUaLdl14BvKADdccVbyoBtALoAaKJwg4IKCABMzUAL6D6dXTKgBUAoISrpGOCactvaOzi4eDFBsHJyygVCsEMBwrAhQAAYqIrwAJGHGqh7RDk4qblBlMbWuHvmyHrLBSgTEpOQAClicIgAW7HASI4kaTArEvPDIaJi4PSQIZJS0-AuIKBjY+ETrmxpCQcey8orAUGt9wACCE4Sb07Szx7tLB6vHDxodrA9stDvcNuQzgAyKD6VD1BBwQgAIwgrE85wA8siAFa1AB0Q04qAkCE+xFscPqAEYAAyefhXLq3LCJcGbQbDYBjdATEZMIrARnXEK3ZFs-4Qp4vTYC1RCqRAA
💻 Code
🙁 Actual behavior
Typescript cannot infer/passthrough the type parameter in ComponentAugment
🙂 Expected behavior
It should resolve ComponentAugment the same way it does with ComponentPassthrough, but with the added id property in this case. The expected type of b in this example should be:
Additional information about the issue
No response