microsoft / microsoft/TypeScript

Not possible to have optional object property compatible with both Closure Compiler and Intellisense

Aperta
#30,522 1 commento 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Needs Proposal Suggestion
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:

  1. Enable "checkJs": true in jsconfig.json.
  2. Create a Javascript file:
class A {

  /**
   * @param {{field: string|undefined}} obj 
   */
  constructor(obj) {
    this.obj = obj;
  }
}

let a = new A({});

Results in this error:
image

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

  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 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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.