-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Default generic type variables #2175
Copy link
Copy link
Closed
Labels
CommittedThe team has roadmapped this issueThe team has roadmapped this issueFixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Metadata
Metadata
Assignees
Labels
CommittedThe team has roadmapped this issueThe team has roadmapped this issueFixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript
Type
Fields
Give feedbackNo fields configured for issues without a type.
It would be really useful if I could set default values for my generic type variables. In many cases, the users of my class don't want to use a different value and so it's cumbersome to having to type it in.
If I could do this:
then the people who don't care about the type of
userData(because they don't use it) and the people who are fine with it being aStringdon't have to set a generic type but others can if they want.Also, these type variables could default to
anyor the type they extend (if they do) without explicitly defaulting them.For example:
<T extends MyClass>would default toMyClass(without explicitly writing it)and
<T>could default toanyWhat do you think?