-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Closed
Copy link
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
Bug Report
π Search Terms
instantiation expressions, question mark, jsdoc nullable, any, Java wildcard
π Version & Regression Information
- This is the behavior in every version since Instantiation expressionsΒ #47607 introduced instantiation expressions (TypeScript 4.7 and up)
β― 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.
thorn0fatcerberus and jsejcksn
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue