Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javascript+Jsdoc: Not possible to distinguish an omitted type parameter from explicitly specified any. Discrepancy to Typescript: There the omitted type parameter gets typed unknown, and is thus distinguishable #60786

Open
gima opened this issue Dec 17, 2024 · 0 comments

Comments

@gima
Copy link

gima commented Dec 17, 2024

🔎 Search Terms

"jsdoc" AND "type parameter" AND "unknown" AND "any" AND ("missing" OR "omitted")

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about this.
  • The required syntax got support from 4.7.4 onwards.
  • Tried versions: Nightly(v5.8.0-dev.20241217), Stable (5.7.2), Oldest supporting (4.7.4).

⏯ Playground Link

Below.

💻 Code

JavaScript + Typed with JSDoc

🔗 Playground link (stable v5.7.2, language:js)

/**
 * @template T
 */
function create() {}

const      gNo = /** @type {typeof create         } */ (create);
const     gAny = /** @type {typeof create<any>    } */ (create);
const  gString = /** @type {typeof create<string> } */ (create);
const gUnknown = /** @type {typeof create<unknown>} */ (create);

     gNo(); // const      gNo: <any    >() => void // <-- Take note! Type is "any"!
    gAny(); // const     gAny: <any    >() => void
 gString(); // const  gString: <string >() => void
gUnknown(); // const gUnknown: <unknown>() => void

TypeScript

🔗 Playground link (stable v5.7.2, language:ts)

function create<T>() {}

const      gNo = create;
const     gAny = create<any    >;
const  gString = create<string >;
const gUnknown = create<unknown>;

     gNo(); // const      gNo: <unknown>() => void // <-- Take note! Type is "unknown"!
    gAny(); // const     gAny: <any    >() => void
 gString(); // const  gString: <string >() => void
gUnknown(); // const gUnknown: <unknown>() => void

🙁 Actual behavior

🪢 Javascript + Typed with JSDoc:
Behaves incorrectly ❌.
Here it's NOT possible to distinguish a missing type parameter from that of explicitly given any.
Furthermore, the need to use this distinction arose, because the ' "noImplicitAny": true ' does NOT warn of the missing type parameter.

🪢 Typescript:
Behaves correctly ✅.
Here it IS possible to distinguish a missing type parameter from that of explicitly given any.
Though here, too, the ' "noImplicitAny": true ' does NOT warn of the missing type parameter.

🙂 Expected behavior

When using JavaScript+Jsdoc, a missing type parameter should be unknown, not any .
That's the way it is already with TypeScript.

Both cases should behave the same, since the type checking is performed by the same system.

Additional information about the issue

No response

@gima gima changed the title Javascript+Jsdoc: Not possible to distinguish an omitted type parameter from any. Discrepancy to Typescript: The type parameters becomes unknown, and is thus distinquishable Javascript+Jsdoc: Not possible to distinguish an omitted type parameter from any. Discrepancy to Typescript: The type parameters is unknown and is thus distinguishable Dec 17, 2024
@gima gima changed the title Javascript+Jsdoc: Not possible to distinguish an omitted type parameter from any. Discrepancy to Typescript: The type parameters is unknown and is thus distinguishable Javascript+Jsdoc: Not possible to distinguish an omitted type parameter from explicitly specified any. Discrepancy to Typescript: There the omitted type parameter gets typed unknown, and is thus distinguishable Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant