Microsoft/TypeScript

typeof Foo['bar'] has strange precedence

Open

#19 707 ouverte le 3 nov. 2017

Voir sur GitHub
 (6 commentaires) (0 réactions) (0 assignés)TypeScript (6 726 forks)batch import
Effort: ModerateExperimentation NeededHelp WantedRevisitSuggestion

Métriques du dépôt

Stars
 (48 455 stars)
Métriques de merge PR
 (Merge moyen 6j 17h) (9 PRs mergées en 30 j)

Description

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?

Guide contributeur