Microsoft/TypeScript

typeof Foo['bar'] has strange precedence

Offen

#19.707 geöffnet am 03.11.2017

 (6 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (13.395 Forks)batch import
Effort: ModerateExperimentation NeededHelp WantedRevisitSuggestion

Repository-Metriken

Stars
 (108.860 Sterne)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

Type queries combined with indexed access types currently produce a parse tree that is surprising in its behavior.

One would think that typeof Foo['bar'] would be parsed as typeof (Foo['bar']), which would really be something like typeof Foo.bar.

That's not the case. It's actually parsed as (typeof Foo)['bar'].

Conveniently, it seems that semantically (when type-checking) these are identical, but it seems strange for syntactic consumers. Do we believe this is currently working as intended?

Contributor Guide