microsoft / microsoft/TypeScript

Semantic highlighting: Non-explicit readonly properties not shown as such

Offen
#56,563 0 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

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

Beschreibung

🔎 Search Terms

readonly, readonly properties

🕗 Version & Regression Information

Nothing to put in here, has never worked, I don't think.

Might be a language server issue, idk

⏯ Playground Link

https://www.typescriptlang.org/play#code/CYUwxgNghgTiAEYD2A7AzgF3lAXPA3gFACQcUwqEAntgEZigBmeKArgLa0gyEC+hUAHRR6TQqEiwEydFlp4ASiHKUqAHiLERDEM3htO3PgD5CtYaN3jw0OIlSZEefPDIUU1Ojr0YYrBLzwAD4ErsruntpMeIxQEGgBhGAW3oQAlozwABTJUboAlAQkuZaMfEnQaGjwACJFxADmIFh5jFmFmqTNrDAo8ACMJPz8ErbSDljAeDXiKWJAA

💻 Code

In this example, there are 4 variables, all with a readonly property called abcdef, only the first one is registered by the IDE as being readonly, even though they are.

declare const a: {
	readonly abcdef: number
}
a.abcdef
declare const b: Readonly<{
	abcdef: number
}>
b.abcdef
declare const c: { readonly abcdef: true } | { readonly abcdef: false }
c.abcdef
if (c.abcdef) {
	c.abcdef
}
class D {
	get abcdef() {
		return 1
	}
}
declare const d: D
d.abcdef
🙁 Actual behavior

This is an IDE issue regarding code highlighting. When a property is readonly, but not explicitly so, it doesn't show up as a readonly property. TypeScript knows it's readonly, but the syntax highlighting doesn't always match it, which can be a bit confusing, just like if consts didn't always have the different highlighting. It's a lot nicer when you can always immediatly tell when something is readony, not by having to test it out and it makes it a lot more readable.

🙂 Expected behavior

All the properties should be registered as readonly, in the case of VSCode, the same colour as constants

Additional information about the issue

No response

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

Reproduziere das Verhalten der semantischen Hervorhebung anhand des verlinkten TypeScript Playground-Beispiels und untersuche die entsprechende VSCode-Hervorhebung. Vergleiche die vier Fälle mit readonly-Eigenschaften, einschließlich Readonly, Unions und des Getters, und betrachte das Issue als abgeschlossen, wenn jede readonly-Eigenschaft erwartungsgemäß konsistent hervorgehoben wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
tooling
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

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