Closed as not planned
Description
π 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
π» Code
type FunctionalComponent<T> = (props: T) => string;
const test = <T>(props: { values: T[], selected: T }) => {
const {values, selected} = props;
return `test: ${values}, selected: ${selected}`;
};
const ComponentPassthrough = <T>(comp: FunctionalComponent<T>): FunctionalComponent<T> => comp;
const ComponentAugment = <T>(comp: FunctionalComponent<T>): FunctionalComponent<T> & { id: number } => Object.assign(comp, { id: 10 });
const a = ComponentPassthrough(test);
const b = 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