Microsoft/TypeScript

typeof Foo['bar'] has strange precedence

開放

#19,707 建立於 2017年11月3日

 (6 則留言) (0 個反應) (0 位負責人)TypeScript (13,395 個分叉)batch import
Effort: ModerateExperimentation NeededHelp WantedRevisitSuggestion

倉庫指標

星標
 (108,860 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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?

貢獻者指南