kaleidawave / ezno

A JavaScript compiler and TypeScript checker written in Rust with a focus on static analysis and runtime performance
https://kaleidawave.github.io/posts/introducing-ezno/
MIT License
2.3k stars 42 forks source link

Tuple modification by method diagnostics #170

Open kaleidawave opened 1 week ago

kaleidawave commented 1 week ago

Currently tuple annotations also make their length a constraint.

So the following fails because { ... length: 3 } is not assignable to { ... length: 2 }

const x: [1, 2] = [1, 2, 3]

This is TSC behavior for all subtyping


Now thanks to #18 and .push unfolding. x.push(5) currently fails because it tries to assign to the length.

The problem is this just raises the usual Parameter assignment mismatch. It would be good if it could detect the constraint is a tuple and the length is being modified then it could throw a different diagnostic?

The one problem is that currently pop also tries to modify the value, so two assignment mismatches are thrown. Maybe events could short-circuit? Or go into unknown mode? Or don't print the second assignment mismatch? Or something?