TScert: A Sound Core for TypeScript github.com · 20 points · 7 comments · HN thr...

@best

TScert: A Sound Core for TypeScript github.com · 20 points · 7 comments · HN thread

TL;DR TScert is a research checker for TypeScript functions that accepts a function only when an untrusted producer's type claims come with a certificate that a checker, with its soundness proved in Lean, validates. It targets the unsoundness of tsc (any, assertions, unchecked index reads) and gives a guarantee that accepted functions never apply operations to ill-fitting values or return values outside their result type, though it may throw or loop. The README reports 643 of 686 functions in its own tools/ directory verifying at v0.94.

  • Its example is a function that reads xs[n - 1] after xs.pop(); tsc accepts it under strict without noUncheckedIndexedAccess, while TScert rejects it and accepts the version declaring string | undefined.
  • An OCaml producer proposes types for expressions, and an untrusted search proposes a derivation; the Lean checker validates the derivation against its own translation, so no proposed type is trusted.
  • The theorem checkUnitJson_safe says accepted functions do not get stuck and do not return values outside their result type; throwing and non-termination are allowed.
  • Trusted rather than proved: the TypeScript-to-calculus translation, library and host function contracts, caller and import types, and Lean itself.
  • Supported subset includes classes, closures, generics, async/await of native promises, and try/catch; any, type assertions, and unsupported forms are refused with a reason and location.
  • The project is explicitly unfinished research, and its license adds a clause excluding use of the code for training machine-learning systems.

Discussion The thread is short and mostly skeptical. Commenters question whether the guarantee adds anything beyond what tsc already checks, ask for examples of bugs tsc misses, and debate whether TypeScript's type system can be sound at all given JavaScript semantics such as Proxies. The tone is critical and somewhat dismissive, with one commenter pointing out that the soundness claim is stated in the README's second paragraph.

  • TypeScript's unsoundness makes a sound checker questionable (many): Commenters argue TypeScript deliberately pretends JavaScript behaves in ways it does not, so a proof built on TypeScript's types inherits those lies. One predicts that modelling real JavaScript, including Proxy behavior, would expose most existing programs as possibly wrong.
  • Asks what new bugs it catches beyond tsc (some): Some want concrete cases that the existing compiler misses, and one asks whether the guarantee about results is already covered by TypeScript's checker.
  • Type system should reject code that breaks soundness (a few): One commenter asks why TypeScript itself does not reject code that undermines its type system. A reply says that closely typed TypeScript does track JavaScript behavior and that tsconfig options can forbid implicit null or undefined.
  • The soundness scope is already stated in the README (a few): One commenter notes that the README addresses soundness in its second paragraph, implying the original objection missed the stated scope.

#TypeScript #formalVerification #Lean #typeSoundness #staticAnalysis