microsoft / microsoft/TypeScript
Assigning a @type to an async function emits an error
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
ts1065 jsdoc async return promise
🕗 Version & Regression Information
- This changed between versions
5.1.6and5.2.2
⏯ Playground Link
💻 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked TypeScript Playground repro and compare the diagnostics for the JSDoc and TypeScript examples across the reported versions. Trace the JavaScript JSDoc type-checking entry point, add regression coverage for the async function assignment, and verify that neither example emits an error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100