tree-sitter / tree-sitter-typescript

TypeScript grammar for tree-sitter
MIT License
361 stars 108 forks source link

Fix lookup type precedence #150

Closed nbrahms closed 3 years ago

nbrahms commented 3 years ago

The typeof keyword has a slightly unexpected precedence in a typed context. That is,

type Foo = typeof my_array[number]

should be interpreted as

type Foo = ((typeof my_array)[number])

This commit fixes this grammar to have the above precedence.

This can be confirmed by attempting to type-check the following code:

const my_array = ["a", "b", "c"]; type MA = (typeof my_array)[number]; // MA = "string" type MB = typeof (my_array[number]); // throws errors

Note that this leaves a similar issue (#149) with keyof lookups unresolved.

Fixes #141.

maxbrunsfeld commented 3 years ago

Thanks!