microsoft / microsoft/TypeScript

jsdoc: escaped property names are not parsed properly

Aperta
#54,898 10 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Experience Enhancement Help Wanted Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

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

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 il TypeScript Playground collegato e l’esempio JSDoc che mostra un # con escape in un nome di proprietà. Traccia come vengono analizzati e verificati il typedef JSDoc e il literal di oggetto; il lavoro è completato quando l’esempio non produce errori e riconosce x5t#S256 come proprietà dichiarata.

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

Valutazione

Stack tecnologico
javascript, typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
42/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.