You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Question marks (JSDoc types) allowable in instantiation expression type arguments #51802
No compiler errors. The question marks seem to be treated like JSDoc nullable types and a question mark by itself seems to be interpreted as any (not sure if that's true for JSDoc either).
🙂 Expected behavior
Compiler errors on every question mark, saying that it's not valid, perhaps with a "JSDoc types are not allowed here" message.
This Stack Overflow question is asking about how to use the Java wildcard syntax in TypeScript, and I'm like 🤯. Apparently this was suggested by VSCode type hints. I don't know much about JSDoc but I assume some support for it has accidentally leaked into instantiation expression checking.
If your codebase forbids use of any (and there are definitely good reasons to do so!) then using an undocumented TS bug to instantiate a ModuleBase<any, any> feels like cheating and probably shouldn't pass code review.
If your codebase forbids use of any (and there are definitely good reasons to do so!) then using an undocumented TS bug to instantiate a ModuleBase<any, any> feels like cheating and probably shouldn't pass code review.
I just detected the possibility of using question marks and asked about it on SO, which in turn let to this issue here. Additionally, it solved my problem at hand and it's not yet clear if it is a bug ¯\(ツ)/¯
That's fair, though it definitely feels like a bug since ? doesn't work as an alias for any in any other context and TS doesn't have existential types (what Foo<?> would be most likely to denote if that syntax were officially supported).
Activity
mike-lischke commentedon Dec 7, 2022
Note that without the question marks my code does not compile.
jcalz commentedon Dec 7, 2022
Nor should it. You can change
?toanyto get it to compile (with all the caveats that come from usingany).mike-lischke commentedon Dec 7, 2022
anyis forbidden in my code base andunknowndoesn't compile.fatcerberus commentedon Dec 7, 2022
If your codebase forbids use of
any(and there are definitely good reasons to do so!) then using an undocumented TS bug to instantiate aModuleBase<any, any>feels like cheating and probably shouldn't pass code review.jcalz commentedon Dec 7, 2022
Mike Lischke (@mike-lischke) That's not really relevant to this issue, unfortunately. By using
?you are essentially usingany. I understand that your workflow depends on spacebar heating but this issue is about the (presumable) bug.MartinJohns commentedon Dec 7, 2022
You control the linter. Don't let the linter control you.
mike-lischke commentedon Dec 7, 2022
I just detected the possibility of using question marks and asked about it on SO, which in turn let to this issue here. Additionally, it solved my problem at hand and it's not yet clear if it is a bug ¯\(ツ)/¯
fatcerberus commentedon Dec 7, 2022
That's fair, though it definitely feels like a bug since
?doesn't work as an alias foranyin any other context and TS doesn't have existential types (whatFoo<?>would be most likely to denote if that syntax were officially supported).We'll see what the maintainers say.
ahejlsberg commentedon Dec 7, 2022
This is definitely a bug. We're forgetting to visit child nodes in
checkExpressionWithTypeArguments.