Suggestion: Allow static members to reference type parameters if they have default types #33870
Closed
5 tasks done
Labels
Declined
The issue was declined as something which matches the TypeScript vision
Suggestion
An idea for TypeScript
Search Terms
default type, default type parameters
Suggestion
This is related to #32211 and especially, #24018. I would have commented on the latter, but it's limited to collaborators. @Andy-MS said:
My proposal is to allow type parameters in static members only if those parameters have default values. For example:
But if you specify a default value, everything makes sense:
Use Cases
In my personal use case, I have an instance property
options
that merges input with data from a staticdefaults
property:If I then extend the class, I get no type-checking for
defaults
:Examples
With my proposal, you could define the base class like this:
The descendant like this:
And the final result would be:
Everything is explicitly defined and typed.
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: