Microsoft/TypeScript

Precedence in parsing types

開放

#7,094 建立於 2016年2月16日

 (5 則留言) (0 個反應) (0 位負責人)TypeScript (13,395 個分叉)batch import
DocsHelp Wanted

倉庫指標

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

描述

It looks to me like this should parse, but it doesn't:

var x: number | (string)=>void;

It works with added parens:

var x: number | ((string)=>void);

But if the parser is not too hacky, then maybe it's easy to make the first work?

(FWIW, I ran into this in a rest argument, where it would be nice to avoid the extra parens in

function foo(...xs: (number | ()=>void)[]): void { }

)

貢獻者指南