{"id":51338544,"url":"https://github.com/jessealama/thales","last_synced_at":"2026-07-02T05:03:34.407Z","repository":{"id":356477703,"uuid":"1218801829","full_name":"jessealama/thales","owner":"jessealama","description":"TypeScript compiler and JavaScript engine in Lean","archived":false,"fork":false,"pushed_at":"2026-06-27T20:42:13.000Z","size":1375,"stargazers_count":57,"open_issues_count":34,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-28T20:05:22.711Z","etag":null,"topics":["javascript","lean4","typescript"],"latest_commit_sha":null,"homepage":"","language":"Lean","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jessealama.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-23T08:25:53.000Z","updated_at":"2026-06-24T09:05:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"494199b6-b3c3-4b8b-9f16-e923b9965abd","html_url":"https://github.com/jessealama/thales","commit_stats":null,"previous_names":["jessealama/thales"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jessealama/thales","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessealama%2Fthales","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessealama%2Fthales/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessealama%2Fthales/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessealama%2Fthales/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jessealama","download_url":"https://codeload.github.com/jessealama/thales/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessealama%2Fthales/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35033497,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-02T02:00:06.368Z","response_time":173,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","lean4","typescript"],"created_at":"2026-07-02T05:03:32.735Z","updated_at":"2026-07-02T05:03:34.399Z","avatar_url":"https://github.com/jessealama.png","language":"Lean","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Thales\n\nA TypeScript-to-Lean 4 compiler. Thales type-checks a safe subset of\nTypeScript and emits a Lean 4 sidecar alongside the input `.ts` file,\nturning your TypeScript module into a Lean module you can reason\nabout.\n\n**Thales sits on top of strict TypeScript.** Every program Thales\naccepts is also accepted by `tsc --strict` — we don't invent new\nsyntax or reinterpret existing type rules, so your editor tooling,\nIDE integrations, and CI linters keep working. What Thales _does_ is\nfurther restrict TS (rejecting mutation, classes, async, untyped\nescapes, etc.) and enrich selected patterns — nullable unions,\n`@throws`, `@total` — with Lean-visible semantics that TypeScript's\nown type system cannot express. The result: a narrow, disciplined\nsubset of TS whose emitted Lean you can actually reason about.\n\n## A quick taste\n\n```typescript\ntype User = { name: string; age: number };\n\n/** @throws RangeError when age is negative */\nfunction makeUser(name: string, age: number): User {\n  if (age \u003c 0) throw new RangeError('age must be non-negative');\n  return { name, age };\n}\n\ntype NameList = { kind: 'nil' } | { kind: 'cons'; head: User; tail: NameList };\n\n/** @total */\nfunction firstName(xs: NameList): string | null {\n  switch (xs.kind) {\n    case 'nil':\n      return null;\n    case 'cons':\n      return xs.head.name;\n  }\n}\n```\n\nThales type-checks this against a strict subset of TypeScript and\nemits Lean 4 where:\n\n- `makeUser` becomes `def makeUser : String → Int → Except RangeError User`\n  (failure mode visible in the signature; callers must `try`/`catch` or\n  propagate via `@throws`).\n- `firstName` becomes `def firstName : NameList → Option String`\n  (Lean verifies termination from the structural recursion; nullability\n  tracked in the type).\n\n`@throws` and `@total` are mutually exclusive: a `@total` function makes\nthe stronger claim that no failure escapes, so it cannot also declare\none. See [`docs/subset.md`](docs/subset.md#total-and-termination).\n\n## Install\n\n```bash\ngit clone https://github.com/jessealama/thales.git\ncd thales\nlake build thales\n```\n\n## Usage\n\n```bash\n.lake/build/bin/thales foo.ts               # type-check + emit Foo.lean\n.lake/build/bin/thales --no-emit foo.ts     # type-check only\n.lake/build/bin/thales -o \u003cdir\u003e foo.ts      # emit into \u003cdir\u003e/Foo.lean\n.lake/build/bin/thales --overwrite foo.ts   # emit, replacing existing Foo.lean\n```\n\n## Headline features\n\n- **`Option` for nullable types.** `T | null` and `T | undefined` map\n  to `Option T`. Narrowing on `=== null` / `!== null` works.\n- **`@throws` for typed exceptions.** Functions that can throw declare\n  their error types in JSDoc; the emitted Lean returns `Except E T`.\n  `try`/`catch` desugars to a `match` on the `Except`. Catches use the\n  standard TS form (`catch (e)` — untyped, as `tsc --strict` requires);\n  Thales infers the caught type from the `try` body.\n- **`@total` for \"always returns a value\" guarantees.** Default emission\n  is `partial def` — non-total recursion is fine. `@total` is a stronger\n  source-level claim: the function terminates (Lean's termination checker\n  must accept it) _and_ no failure escapes (no uncaught `throw`, no\n  uncaught call into a `@throws` callee). It is mutually exclusive with\n  `@throws`; failures of either kind surface as clean diagnostics\n  (TH0066/TH0067/TH0070).\n- **Built-in bounded number types via `@thales/prelude`.**\n  `Integer`, `Natural`, `Byte`, and `Bit` are branded aliases of\n  `number` in TypeScript and Lean Subtypes of `Float` in the emitted\n  Lean. The chain is `Bit ⊆ Byte ⊆ Natural ⊆ Integer ⊆ number`.\n  Numeric literals are checked at compile time (out-of-range →\n  TH0080); assigning a plain `number` without a guard (`isInteger`,\n  `isNatural`, …) or throwing constructor (`asInteger`, `asNatural`,\n  …) is rejected with TH0081. Arithmetic operators always widen to\n  `number`; narrow the result with a guard or constructor if you\n  need the refinement type back. The bounded number types reflect\n  into Lean's `Int`/`Nat` so downstream proofs can reason about\n  safe-integer arithmetic — see\n  [`docs/beyond-typescript.md`](docs/beyond-typescript.md) for the\n  picture of what Thales gives you that TypeScript alone cannot.\n\n## What's in the subset\n\nThales accepts a proper subset of what `tsc --strict` accepts. See\n[`docs/subset.md`](docs/subset.md) for the full contract and\n[`docs/errors.md`](docs/errors.md) for every `TH####` diagnostic code.\nCurrently out: classes, mutation, async, `any`/`unknown`/intersection\ntypes. See [`docs/future.md`](docs/future.md) for the roadmap.\n\n## Generated Lean modules\n\nEvery emitted file opens with `import Thales.TS.Runtime`. The runtime\nis a small Lean module (`Option'`, `Result`, error records,\n`consoleLog` with JS-compatible number printing, array combinators,\n`parseFloat`/`isNaN`) sized to the accepted subset and designed so\nthat the Lean path's stdout matches the VM path byte-for-byte. See\n[`docs/runtime.md`](docs/runtime.md) for the full surface.\n\nThe runtime's bounded-number-type machinery postulates twelve\nIEEE-754 axioms (covering Float ↔ Int boundary behavior, `Float.abs`,\nand `Integer` reflection) that Lean's stdlib does not provide.\nEmitted code that reasons about safe-integer arithmetic ultimately\nrests on these. See [`docs/axioms.md`](docs/axioms.md) for the full\nlist and rationale.\n\n## Testing\n\n```bash\nnpm run conformance:self-test                # harness regression\nnpm run conformance                          # full conformance corpus\nlake build ThalesTest                        # Lean unit tests\n```\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjessealama%2Fthales","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjessealama%2Fthales","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjessealama%2Fthales/lists"}