-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Description
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:
class MyClass<T = String>
{
public userData: T;
constructor() {}
}
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 a String
don't have to set a generic type but others can if they want.
Also, these type variables could default to any
or the type they extend (if they do) without explicitly defaulting them.
For example:
<T extends MyClass>
would default to MyClass
(without explicitly writing it)
and
<T>
could default to any
What do you think?
watzon, iKBAHT, s-panferov, ToucheSir, sebald and 151 moremetasansanause-strict, ErikCupal, Glavin001 and adrian-moisaMahmoud-Masri, igabesz, wclr, dzsodzso63, JoshuaKGoldberg and 17 more
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