microsoft / microsoft/TypeScript

jsdoc: escaped property names are not parsed properly

Offen
#54,898 10 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Experience Enhancement Help Wanted Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

Bug Report

🔎 Search Terms

jsdoc
escape
property names

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about jsdoc
⏯ Playground Link

Playground link with relevant code

💻 Code
/**
 * @see https://datatracker.ietf.org/doc/html/rfc7517#section-4
 * @typedef {Object} JWK
 * @prop {string} kty key type
 * @prop {string} [x5t\u0023S256] X.509 Certificate SHA-256 Thumbprint
 */

/** @type {JWK} */
const o = {
    kty: 'foo',
    'x5t#S256': 'bar',
};
🙁 Actual behavior

Errors:
]' expected.
Type '{ kty: string; 'x5t#256': string; }' is not assignable to type 'JWK'. Object literal may only specify known properties, and ''x5t#256'' does not exist in type 'JWK'.

🙂 Expected behavior

No errors and to parse escaped property names correctly.

Additional Info

If \u0020 doesn't work on VSCode, file it as an issue with them. The way JSDoc works is to allow such escaping.

And that approach should indeed work with any character as "0020" is the hexadecimal Unicode escape sequence for a space. \u0023 is the code for # (familiarize yourself with Unicode escapes in JavaScript to find for others).

Originally posted by @brettz9 in https://github.com/jsdoc/jsdoc/issues/1468#issuecomment-743490820

Edit: Fixed typo in property name. Incidentally shows the importance of types. 😅

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

Beginne mit dem verknüpften TypeScript Playground und dem JSDoc-Beispiel, das ein maskiertes # in einem Eigenschaftsnamen zeigt. Verfolge, wie der JSDoc-Typalias und das Objektliteral geparst und geprüft werden; abgeschlossen ist die Aufgabe, wenn das Beispiel keine Fehler erzeugt und x5t#S256 als deklarierte Eigenschaft erkennt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, typescript
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
42/100

Neue Issues direkt in Ihr Postfach

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