Microsoft/TypeScript

typeof Foo['bar'] has strange precedence

Open

#19.707 aberto em 3 de nov. de 2017

Ver no GitHub
 (6 comments) (0 reactions) (0 assignees)TypeScript (6.726 forks)batch import
Effort: ModerateExperimentation NeededHelp WantedRevisitSuggestion

Métricas do repositório

Stars
 (48.455 stars)
Métricas de merge de PR
 (Mesclagem média 6d 17h) (9 fundiu PRs em 30d)

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?

Guia do colaborador