microsoft / microsoft/TypeScript
JSDoc: Infer return value of function
Open
Nobody has claimed this yet.
Bug
Domain: JSDoc
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Issue Type: Bug
Typescript works:
type Data = { a: string };
function test<T>(funct: (arg: Data) => T): T {
return funct({a: 'test'});
}
test(a => a.a); // return type: string => works OK
JSDoc bug:
/** @typedef {{ a: string }} Data */
/**
* @template T
* @param { (arg: Data) => T } funct
* @returns {T}
*/
function test(funct) {
return funct({a: 'test'});
}
test((/** @type { Data } */ a) => a.a); // return type: string => works OK
test(a => a.a); // return type: any => not works - BUG
VS Code version: Code 1.55.2 (3c4e3df9e89829dce27b7b5c24508306b151f30d, 2021-04-13T09:36:32.643Z)
OS version: Darwin x64 20.3.0
System Info
| Item | Value |
|---|---|
| CPUs | Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz (8 x 2700) |
| GPU Status | 2d_canvas: enabled gpu_compositing: enabled metal: disabled_off multiple_raster_threads: enabled_on oop_rasterization: enabled opengl: enabled_on protected_video_decode: unavailable_off rasterization: enabled skia_renderer: disabled_off_ok video_decode: enabled webgl: enabled webgl2: enabled |
| Load (avg) | 2, 2, 2 |
| Memory (System) | 16.00GB (0.91GB free) |
| Process Argv | --crash-reporter-id 2e37b1f3-b89a-4c4c-8add-c119edc3cc5b --crash-reporter-id 2e37b1f3-b89a-4c4c-8add-c119edc3cc5b |
| Screen Reader | no |
| VM | 0% |
Extensions (17)
| Extension | Author (truncated) | Version |
|---|---|---|
| vscode-openapi | 42C | 4.5.0 |
| swagger-viewer | Arj | 3.0.1 |
| bracket-pair-colorizer-2 | Coe | 0.2.0 |
| vscode-simpler-icons | dav | 1.6.5 |
| vscode-eslint | dba | 2.1.20 |
| gitlens | eam | 11.4.1 |
| EditorConfig | Edi | 0.16.4 |
| json-tools | eri | 1.0.2 |
| code-runner | for | 0.11.3 |
| jsdoc | lll | 1.0.3 |
| dotenv | mik | 1.0.1 |
| prettify-json | moh | 0.0.3 |
| vscode-typescript-tslint-plugin | ms- | 1.3.3 |
| vscode-yaml | red | 0.18.0 |
| sort-lines | Tyr | 1.9.0 |
| vscode-icons | vsc | 11.4.0 |
| html-css-class-completion | Zig | 1.20.0 |
(3 theme extensions excluded)
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383cf:30185419
pythonvspyt678:30270856
pythonvspyt602cf:30294773
vspor879:30202332
vspor708:30202333
vspor363:30204092
vstry244:30276681
pythonvsnew554cf:30291488
pythontb:30283811
vspre833cf:30267465
pythonptprofiler:30281270
vscnewfilehidden:30294815
vshan820:30294714
pythondataviewer:30285071
vscus158:30286553
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 by reproducing the two TypeScript and JSDoc examples from the issue and compare the inferred return types for the unannotated callback. Trace the JSDoc generic callback inference path and add coverage for the failing example; done means the unannotated callback is inferred to return string rather than any.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100