Add a strict flag forbidding impossible generic declarations #26129
Labels
Add a Flag
Any problem can be solved by flags, except for the problem of having too many flags
Declined
The issue was declined as something which matches the TypeScript vision
Suggestion
An idea for TypeScript
Search Terms
generic declaration return type parameter
Suggestion
Today you can write declarations like this:
This isn't particularly meaningful -
getThing
has no plausible correct implementation that doesn't rely on the caller asking for the correct type by coincidence.We then also started allowing this to enable some other scenarios (#16072):
See also #5256 (comment)
The rule should be: All type parameters must appear in an input position; this would need to be under some flag like
--strictTypeParameterDeclarations
(please bikeshed).Users should return
any
orunknown
instead in these cases.A lint rule approximating this can be done syntactically so we should scan DefinitelyTyped to see what the breakage would look like.
Use Cases
Mostly to allow us to clean up DefinitelyTyped.
Examples
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: