microsoft / microsoft/TypeScript
Not possible to have optional object property compatible with both Closure Compiler and Intellisense
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
- VSCode Version: 1.32.3 x64
- OS Version: Ubuntu 18.04
Steps to Reproduce:
- Enable "checkJs": true in jsconfig.json.
- Create a Javascript file:
class A {
/**
* @param {{field: string|undefined}} obj
*/
constructor(obj) {
this.obj = obj;
}
}
let a = new A({});
Results in this error:

Adding error text here for duplicate detection:
Argument of type '{}' is not assignable to parameter of type '{ field: string; }'.
Property 'field' is missing in type '{}' but required in type '{ field: string; }' .ts(2345)
Does this issue occur when all extensions are disabled?: Yes
Expected behaviour:
Some way to mark object properties as optional compatible both with Closure Compiler and VsCode intellisense. Either through @typedef, through structural interfaces with @record, direct @param notation using string|undefined, or something similar.
This notation works fine today, but it is not recognized by Closure Compiler. It is debatable whether this is an issue with Intellisense or lacking support from Closure Compiler.
class A {
/**
* @param {AParam} obj
*/
constructor(obj) {
this.obj = obj;
}
}
/** @typedef {{field?: string|undefined}} */
var AParam;
let a = new A({});
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con la riproduzione in jsconfig.json usando checkJs e le forme JSDoc @param e @typedef mostrate nel report. Confronta il modo in cui TypeScript gestisce la notazione delle proprietà opzionali con il requisito di compatibilità dichiarato per Closure Compiler. Il lavoro è completato quando una notazione supportata consente new A({}) senza l’errore segnalato di proprietà mancante, mantenendo al contempo la compatibilità con Closure Compiler.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, typescript
- Ambito
- compilers, developer-experience
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100