tree-sitter / tree-sitter-typescript

TypeScript grammar for tree-sitter
MIT License
360 stars 109 forks source link

Support predefined types in type predicates #214

Closed aryx closed 2 years ago

aryx commented 2 years ago

In function (): object {...} object is a predefined type, but in function (object: any): object is foo{} object is now a regular identifier. The previous grammar was not able to parse the second example, probably because when the parser sees the second ':' for the return type, the contextual lexer does not know yet if it's a type predicate or predefined type, so it accepts 'object' as a predefined type and only fails later when it sees 'is'.

test plan:

I tried in astexplorer.net and the second example is valid typescript code (sadly).

Checklist: