Microsoft/TypeScript

Precedence in parsing types

Open

#7,094 创建于 2016年2月16日

在 GitHub 查看
 (5 评论) (0 反应) (0 负责人)TypeScript (48,455 star) (6,726 fork)batch import
DocsHelp Wanted

描述

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 { }

)

贡献者指南