Microsoft/TypeScript

Assigning a @type to an async function emits an error

Open

#58.215 geöffnet am 16. Apr. 2024

Auf GitHub ansehen
 (1 Kommentar) (1 Reaktion) (0 zugewiesene Personen)TypeScript (6.726 Forks)batch import
BugDomain: JSDocHelp Wanted

Repository-Metriken

Stars
 (48.455 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)

Beschreibung

🔎 Search Terms

ts1065 jsdoc async return promise

🕗 Version & Regression Information

  • This changed between versions 5.1.6 and 5.2.2

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.2.2&filetype=js#code/PQKhAIAEBcE8AcCmATRAzcBvAFASnALwB84ACgE4D2AtgJYDOiAPAG6W3IkA+4bHAvuACC9WADsAxgDEx4EMABQC0BBgJEWEeOljB8hRMpj60cNVhbJMwuACGoyeDyESmfkA

💻 Code

JSDoc version:

/** @typedef {() => Promise<void> | void} AsyncFn */

/** @type {AsyncFn} */
const myAsyncFn = async () => {}

TypeScript equivalent:

type AsyncFn = () => Promise<void> | void;

const myAsyncFn : AsyncFn = async () => {}

🙁 Actual behavior

JSDoc version emits an error, TypeScript equivalent does not.

🙂 Expected behavior

Neither should emit an error.

Additional information about the issue

I'm fairly sure this is related to a change from a while back where a new Promise needs to be explicitly marked as returning Promise<void>, which was intentional. But I can't seem to find the related issue anymore so I'm not sure if this is intentional as well.

Either way, the fact that this error is only emitted in JavaScript files seems to suggest that it's a bug.

Contributor Guide