-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Description
Suggestion
π Search Terms
extends conditional constrain
β Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
β Suggestion
short example:
declare function SampleComponent(props: { a?: any; }, context?: any): React.ReactElement<any, any> | null;
declare var Tag1: React.FunctionComponent<{ a?: any; }>;
declare var Tag2: React.FunctionComponent<{}>;
declare var Tag3: typeof SampleComponent;
//Tag1 and Tag3 can assign to each other.
Tag1 = Tag3;
Tag3 = Tag1;
//Tag1 and Tag2 can assign to each other.
Tag1 = Tag2;
Tag2 = Tag1;
//But Tag2 and Tag3 can not assign to each other.
Tag2 = Tag3; //error
Tag3 = Tag2; //error
π Motivating Example
I want to write a function to take any function component that can accept empty props.
function myrender<T extends {}>(Tag: React.FunctionComponent<T>) {
return <Tag /> //error
}
function myrender2(Tag:React.FunctionComponent<{}>)
{
return <Tag/>
}
myrender2(Tag3); //error
π» Use Cases
Metadata
Metadata
Assignees
Labels
No labels