Microsoft/TypeScript

Precedence in parsing types

Aperta

#7094 aperta il 16 feb 2016

 (5 commenti) (0 reazioni) (0 assegnatari)TypeScript (13.395 fork)batch import
DocsHelp Wanted

Metriche repository

Star
 (108.860 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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

)

Guida contributor