[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-108465":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":15,"stars7d":12,"stars30d":16,"stars90d":15,"forks30d":15,"starsTrendScore":15,"compositeScore":17,"rankGlobal":9,"rankLanguage":9,"license":18,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":19,"hasPages":21,"topics":22,"createdAt":9,"pushedAt":29,"updatedAt":30,"readmeContent":31,"aiSummary":32,"trendingCount":15,"starSnapshotCount":15,"syncStatus":33,"lastSyncTime":34,"discoverSource":35},108465,"TScert","cristianoc\u002FTScert","cristianoc","TScert: a sound core for TypeScript. An independent checker, whose soundness is proved in Lean, accepts a TypeScript function only with a proof.",null,"TypeScript",150,3,1,19,0,29,46.21,"Other",false,"main",true,[23,24,25,26,27,28],"formal-verification","lean4","proof-carrying-code","type-safety","type-systems","typescript","2026-11-23 20:06:36","2026-11-17 04:11:48","\u003Cp align=\"center\">\n  \u003Cpicture>\n    \u003Csource media=\"(prefers-color-scheme: dark)\" srcset=\"assets\u002Freadme\u002Flockup-dark.png\">\n    \u003Cimg src=\"assets\u002Freadme\u002Flockup-light.png\" width=\"410\" alt=\"TScert: a sound core for TypeScript\">\n  \u003C\u002Fpicture>\n\u003C\u002Fp>\n\nTScert checks that TypeScript functions are type-safe, and accepts a function\nonly with a proof. A checker whose soundness is proved in Lean validates that\nproof. It never trusts the types that TypeScript or the proposing tools infer;\nwhat it does trust is listed under [What acceptance means](#what-acceptance-means).\n\nhttps:\u002F\u002Fgithub.com\u002Fuser-attachments\u002Fassets\u002Fc539cf25-8956-4bd5-88ca-795873acab34\n\n## Why\n\nTypeScript's type checker is deliberately unsound in places: `any`, type\nassertions, unchecked index reads and covariant arrays let programs that pass\n`tsc` still read `undefined` where a type says `string`. TScert gives a stronger\nanswer for the code it accepts: for every input that meets its annotations, the\nfunction's translation into a formal model never applies an operation to a value\nit does not fit, and never returns a value outside its result type. A theorem in\nLean states that guarantee, and the checker that decides acceptance is the code\nthe theorem is about.\n\n## An example\n\n\u003Cimg src=\"assets\u002Freadme\u002Fchecker.png\" width=\"110\" align=\"right\" alt=\"The checker, a turnstile with a magnifying glass\">\n\nTypeScript accepts this function (under `strict`, which leaves\n`noUncheckedIndexedAccess` off). TScert refuses it:\n\n```ts\nexport function stale(xs: string[]): string {\n  const n = xs.length;\n  xs.pop();\n  return xs[n - 1]; \u002F\u002F past the end after the pop: undefined at run time\n}\n```\n\nAbridged output (offsets refer to the example file):\n\n```text\n\"status\": \"unverified\"\nreject: source expression obligation at [219,228): evidence search failed: no derivation of its return-contract claim\nobligation: The available claim for xs[n - 1] is undefined | string. This return requires string.\n```\n\nWith the result type stated honestly, `string | undefined`, TScert accepts it.\n\nTypeScript's `noUncheckedIndexedAccess` refuses `stale` too, by typing every\nindex read `string | undefined`. It then refuses this loop as well, whose read\nthe condition `i \u003C xs.length` keeps in bounds; TScert verifies it:\n\n```ts\nexport function total(xs: string[]): number {\n  let n = 0;\n  for (let i = 0; i \u003C xs.length; i++) n += xs[i].length; \u002F\u002F flag: possibly 'undefined'\n  return n;\n}\n```\n\nTypeScript accepts the next function under every flag, since it relates arrays\ncovariantly. The `push` puts a number in `xs`, and under Node `toUpperCase`\nthrows a `TypeError`. TScert refuses the assignment, as a writable array is\ninvariant in its element type:\n\n```ts\nexport function shout(xs: string[]): string[] {\n  const ys: (string | number)[] = xs;\n  ys.push(1);\n  return xs.map((x) => x.toUpperCase());\n}\n```\n\nEach is a pipeline case:\n[`invalid-array-last-after-pop.ts`](pipeline\u002Fexamples\u002Finvalid-array-last-after-pop.ts),\n`afterPop` in [`array-last-element.ts`](pipeline\u002Fexamples\u002Farray-last-element.ts),\n[`array-index-loop.ts`](pipeline\u002Fexamples\u002Farray-index-loop.ts) and\n[`invalid-array-covariance.ts`](pipeline\u002Fexamples\u002Finvalid-array-covariance.ts).\n\n## How it works\n\n\u003Cpicture>\n  \u003Csource media=\"(prefers-color-scheme: dark)\" srcset=\"diagrams\u002Farchitecture-dark.png\">\n  \u003Cimg src=\"diagrams\u002Farchitecture-light.png\" alt=\"Parse, plan and elaborate are trusted on review; propose and search are proposals that may be wrong; check is proved sound and receives the certificate and the same request elaboration produced.\">\n\u003C\u002Fpicture>\n\nA front end on TypeScript's compiler API reads the source and the\ndeclarations it uses, and Lean plans its execution. An OCaml program, the\n*producer*, proposes the type of every expression and variable; its answers\nare *claims*, and none is trusted. Lean translates the function, with those\ntypes, into a small formal language (the *calculus*) whose execution and\nsafety are defined in Lean. An untrusted search proposes a *certificate*, a\nderivation that the program meets its types, and the checker validates it\nagainst the same translation. [The stages](docs\u002FDESIGN.md#stages) describe\neach step.\n\n## What acceptance means\n\nAcceptance proves, of the function's translation into the calculus, that for\ninputs and a heap meeting their declared types it does not get stuck and does\nnot return a value outside its result type. It may throw or run forever. The\ntheorem is\n[`checkUnitJson_safe`](lean\u002FVerification\u002FSource\u002FClaims\u002FJson.lean). Some things are\ntrusted rather than proved:\n\n- that the translation from TypeScript to the calculus is faithful (reviewed and\n  tested, not proved);\n- that library and host functions behave as their reviewed contracts state;\n- that callers and imports meet their declared types;\n- Lean itself.\n\nThe [trust surface](docs\u002FDESIGN.md#trust-surface) lists every assumption, and\n[what \"verified\" means](docs\u002FDESIGN.md#what-verified-means) states the guarantee\nexactly.\n\n## Questions\n\n**TypeScript is unsound. How can a checker of it be sound?** TScert has its own\nsemantics of the code: a calculus with a semantic model, in which each operation\nhas its JavaScript meaning. A function TypeScript accepts only by an unsound\nrule, such as covariant arrays, has no proof there, and TScert refuses it. The\nopen question is how much ordinary code it accepts.\n\n**Does a stricter `tsconfig` give the same guarantee?** No configuration is\nsound. [An example](#an-example) shows a flag that refuses a safe loop along\nwith the unsafe read, and a function that every flag accepts and that throws\nunder Node. Bivariant method parameters are another unsound rule no flag closes\n([`invalid-set-covariant.ts`](pipeline\u002Fexamples\u002Finvalid-set-covariant.ts)).\n\n**What does a proof look like?** A certificate, checked by a program proved\nsound once. The front end lowers each function to a program graph, a producer\nproposes a type for each program point, a search derives those claims from the\ncalculus's typing rules, and the checker validates the derivation\n([How it works](#how-it-works)). Nobody writes a proof by hand: a person or an\nagent runs TScert as they run `tsc`.\n\n**What does the proof assume about JavaScript?** No object is a proxy, standard\nbuilt-in prototypes keep their standard methods, values at a declared type are\nplain data objects whose fields are data properties, and library and host\nfunctions meet their reviewed contracts. The\n[trust surface](docs\u002FDESIGN.md#trust-surface) states each assumption and what\nrelies on it.\n\n**What blocks the remaining functions, and is any of it out of reach in\nprinciple?** Nothing found so far is out of reach. Each refusal is a\npattern the calculus has no rule for yet, a library function with no reviewed\nmodel, or code whose invariant is left implicit. The first is closed by a rule\nwith its soundness proof, the second by a model audited against the real\nimplementation, the third by rewriting the code to state the invariant. What\nremains open is cost: a rule's complexity weighed against how much code uses the\npattern, and some patterns are better rewritten than supported. The\n[gap priorities](docs\u002Fdeep-dives\u002Fgap-priorities) rank the refusals of TScert's\nown front end by the code they hold back.\n\n**Is it a replacement for TypeScript?** It checks ordinary TypeScript source,\nread through the TypeScript compiler's own API, and the code it accepts compiles\nand runs as before.\n\n## Status\n\nTScert is a research prototype, built to illustrate ideas and unfinished by\ndesign. Its benchmark is its own\nfront end: at [v0.94](https:\u002F\u002Fgithub.com\u002Fcristianoc\u002FTScert\u002Freleases\u002Ftag\u002Fv0.94),\n643 of the 686 functions of `tools\u002F` verify, each checked in its own unit\nwith what it calls read at its stated signature (census of `ae20a6c6`,\n2026-11-04). The [coverage metrics](docs\u002FDESIGN.md#function-coverage-and-release-thresholds)\nand the [status table](WORK.md#status) give the definitions and the dated\nmeasurements.\n\nIn outline, the supported subset covers:\n\n- `const`\u002F`let`, patterns, `if`, `switch`, loops including `for...of` and\n  `for...in`, labeled blocks, `throw` and `try`\u002F`catch`\u002F`finally`;\n- primitives with literal types, arithmetic, comparisons, template literals,\n  `typeof`, `in`, `instanceof` and strict equality;\n- object literals with spreads, records, index signatures, arrays and tuples,\n  optional chaining, enums, and classes with fields, methods and a base class;\n- functions, closures, optional, default and rest parameters, generic functions\n  certified for every admissible type argument, `async` and `await` of native\n  promises;\n- declared types: aliases, interfaces, unions, intersections and library types\n  through reviewed contracts.\n\n`any` is refused, and a type assertion (`e as T`, `e!`) decides nothing. Every\nunsupported form is refused with a reason and a location. The\n[fragment boundary](docs\u002FSOURCE-FRAGMENT.md#fragment-boundary) lists what is\nrefused and why.\n\n## On the shoulders of\n\nTScert builds on decades of work on types and semantics, among them\n[Appel and McAllester's indexed model](docs\u002FREFERENCES.md#appel-and-mcallester-2001)\nfor foundational proof-carrying code,\n[Ahmed's semantics of types for mutable state](docs\u002FREFERENCES.md#ahmed-2004),\n[Wright and Felleisen's syntactic type soundness](docs\u002FREFERENCES.md#wright-and-felleisen-1994),\n[Reynolds's parametricity](docs\u002FREFERENCES.md#reynolds-1983),\n[Abadi and Cardelli's theory of objects](docs\u002FREFERENCES.md#abadi-and-cardelli-1996),\n[semantic subtyping](docs\u002FREFERENCES.md#frisch-castagna-and-benzaken-2008),\n[JSCert](docs\u002FREFERENCES.md#bodin-et-al-2014-jscert), the\n[ECMAScript specification](docs\u002FREFERENCES.md#ecma-262) and\n[Lean 4](docs\u002FREFERENCES.md#lean-4). [REFERENCES](docs\u002FREFERENCES.md) lists\nevery work, with what TScert takes from it and where.\n\n## Try it\n\nPrerequisites: Node at the version [`.nvmrc`](.nvmrc) pins, the pinned [Lean toolchain](lean\u002Flean-toolchain), OCaml\nand Dune ([the producer guide](ocaml-producer\u002FREADME.md#try-it)). Then:\n\n```sh\nmake setup                                   # node dependencies\nmake build                                   # the Lean verifier and the OCaml producer\nmake check FILE=pipeline\u002Fexamples\u002Farray-last-element.ts\n```\n\n`make check` prints the outcome and the directory holding the run's documents:\nthe source, the parser's output, the producer's claims and the certificate.\n\n## Develop\n\n```sh\nmake test        # both below\nmake test-checks # fast checks and the controls (forged documents and claims)\nmake test-cases  # every pipeline case: source files with their expected outcome\nmake help     # every target\n```\n\n## Read next\n\n- [DESIGN](docs\u002FDESIGN.md): principles, architecture, the trust surface, and the\n  [documentation map](docs\u002FDESIGN.md#documentation-map) of every document.\n- [SEMANTICS](docs\u002FSEMANTICS.md), [POSITIVE-TYPES](docs\u002FPOSITIVE-TYPES.md),\n  [PROGRAM-TYPING](docs\u002FPROGRAM-TYPING.md): the calculus, its types and its\n  typing rules.\n- [SOURCE-MODEL](docs\u002FSOURCE-MODEL.md),\n  [SOURCE-ELABORATION](docs\u002FSOURCE-ELABORATION.md),\n  [SOURCE-CONTRACTS](docs\u002FSOURCE-CONTRACTS.md),\n  [SOURCE-FRAGMENT](docs\u002FSOURCE-FRAGMENT.md): how TypeScript values and\n  operations map to the calculus, how each source form lowers, how types and\n  library contracts are read, and what the fragment refuses.\n- [AGENTS](AGENTS.md): the rules for changing the project: what a change\n  must carry, which tests to keep, and how commits are recorded.\n- [WORK](WORK.md): open work and its status.\n- [Pipeline cases](tests\u002FREADME.md): worked examples of every supported\n  construct, positive and negative.\n- [REFERENCES](docs\u002FREFERENCES.md): the work TScert draws on.\n\n## License\n\nLicensed under the [NON-AI MIT License](LICENSE): the MIT terms, with the code\nexcluded from use in training or improving machine-learning systems and from\ndatasets for that training, also for its derivatives.\n\nThe copyright holder reserves the rights in this repository against text and\ndata mining, under Article 4(3) of Directive (EU) 2019\u002F790, including for\ntraining or improving machine-learning systems; [ai.txt](ai.txt) states the\nsame reservation in machine-readable form.\n","TScert 是一个面向 TypeScript 的形式化验证工具，旨在提供可证明的类型安全性保障。它不依赖 TypeScript 编译器的类型推断，而是要求每个函数附带由 Lean 4 形式化证明支持的类型安全证据；其核心检查器本身已在 Lean 中被严格证明是声音的（sound）。项目支持对数组索引访问、类型协变\u002F逆变、联合类型等常见 TypeScript 不健全行为进行精确建模与拒绝，并能验证带运行时约束（如循环边界条件）的代码。适用于对关键逻辑要求高置信度类型正确性的场景，如金融系统核心模块、安全敏感库或形式化方法教学与研究。",2,"2026-11-24 04:34:17","CREATED_QUERY"]