escalier-lang / escalier-next

Improved type safety with tight TypeScript interop
https://escalier-lang.github.io/escalier-next/
MIT License
14 stars 0 forks source link

Allow partial destructuring of exact object types #328

Closed kevinbarabash closed 3 months ago

kevinbarabash commented 3 months ago

The PartialDestructuring test case should be:

let [a] = [5, "hello"];
let {b} = {a: 5, b: "hello"};

but is currently

let [a] = [5, "hello"];
let {a: _, b} = {a: 5, b: "hello"};

To fix this, we can check if the object type's Provenance field is a pattern or not. Right now we're using env.IsPatternMatching for this purpose, but we only set IsPatternMatching inside of a pattern matching block. Patterns are used in quite a few other places so the Provenance should be more robust. We just need to remember to set that field consistently when inferring types from patterns.