microsoft / microsoft/TypeScript

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

Offen
#30,522 1 Kommentar 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Needs Proposal Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

  • 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({});

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie mit der Reproduktion in jsconfig.json unter Verwendung von checkJs sowie den im Bericht gezeigten JSDoc-Formen @param und @typedef. Vergleichen Sie, wie TypeScript die Notation für optionale Eigenschaften im Verhältnis zur angegebenen Kompatibilitätsanforderung für Closure Compiler behandelt. Als abgeschlossen gilt die Aufgabe, wenn eine unterstützte Notation new A({}) ohne den gemeldeten Fehler wegen einer fehlenden Eigenschaft ermöglicht und gleichzeitig mit Closure Compiler kompatibel bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, typescript
Bereich
compilers, developer-experience
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.