microsoft / microsoft/TypeScript

JSDoc: Infer return value of function

Aperta
#43,913 3 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Domain: JSDoc
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo i due esempi TypeScript e JSDoc dell’issue e confronta i tipi restituiti inferiti per il callback non annotato. Traccia il percorso di inferenza dei callback generici di JSDoc e aggiungi la coverage per l’esempio che fallisce; il lavoro è completato quando il callback non annotato viene inferito come restituito string invece di any.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.