Skip to content

Question marks (JSDoc types) allowable in instantiation expression type arguments  #51802

Closed
@jcalz

Description

@jcalz

Bug Report

🔎 Search Terms

instantiation expressions, question mark, jsdoc nullable, any, Java wildcard

🕗 Version & Regression Information

⏯ Playground Link

Playground link with relevant code

💻 Code

function foo<T>(x: T): T { return x }
const WhatFoo = foo<?> // (x: any) => any 😕
const HuhFoo = foo<string?> // (x: string | null) => string | null 😲
const NopeFoo = foo<?string> // (x: string | null) => string | null 😵
const ComeOnFoo = foo<?string?> //  (x: string | null) => string | null ¿🤪?

class Bar<T> { constructor(public x: T) { } }
const WhatBar = Bar<?>; // Bar<any> 😕
const HuhBar = Bar<string?>; // Bar<string | null> 😲
const NopeBar = Bar<?string> // Bar<string | null> 😵
const ComeOnBar = Bar<?string?> // Bar<string | null> ¿🤪?

🙁 Actual behavior

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.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions