mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-29 07:04:09 +08:00
A JavaScript `var` took the checker's type of its initializer, which no later write is checked against in a JavaScript file. js-yaml 4.1.1 failed on every timestamp with "a 'string' value is not representable in the target union": its `var fraction = 0` holds the fraction's digits as a string while it pads them (`fraction = match[7].slice(0, 3)`). Every YAML error also threw the "assignment to non-variables" fence instead of the YAMLException, because its error mark is a `var` object literal that gains a member (`mark.snippet = snippet(mark)`). - A `var` whose writes the declared type cannot hold is checked-dynamic, by the rules `let` already uses (jsBindingHasOpenWrites), and so is a `var` whose object literal gains members or carries methods (jsDeclarationExpandsObject, shared with `let` and `const`). - `+=` of a string onto a number or boolean binding (`width += "px"`) counts as such a write, for `var` and `let`. - A JavaScript function that returns such a binding returns a checked-dynamic value (an async one a promise of one) instead of the initializer's type. A string binding that is only appended to stays a string.