Microsoft/TypeScript

typeof Foo['bar'] has strange precedence

Open

#19.707 aperta il 3 nov 2017

Vedi su GitHub
 (6 commenti) (0 reazioni) (0 assegnatari)TypeScript (6726 fork)batch import
Effort: ModerateExperimentation NeededHelp WantedRevisitSuggestion

Metriche repository

Star
 (48.455 star)
Metriche merge PR
 (Merge medio 6g 17h) (9 PR mergiate in 30 g)

Descrizione

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?

Guida contributor