{"id":26521,"library":"ts2nim","title":"ts2nim","description":"A TypeScript to Nim transpiler that converts TypeScript source code (and JavaScript via TypeScript ESTree) into valid, pretty Nim code. The 0.0.31 release is currently in early development with limited semantic analysis; it focuses on syntax translation and basic type mapping (e.g., number→float, Array→seq, null→nil). The tool also generates wrapper code from .d.ts files using importcpp pragmas. Compared to alternatives like dts2nim, ts2nim directly translates full TypeScript sources rather than just type definitions. It is intended to expand Nim's JavaScript backend ecosystem by reusing existing TypeScript/JavaScript libraries. Note that the project does not resolve dependencies and requires manual post-translation adjustments.","status":"active","version":"0.0.31","language":"javascript","source_language":"en","source_url":"https://github.com/bung87/ts2nim","tags":["javascript","typescript","Nim","transpiler"],"install":[{"cmd":"npm install ts2nim","lang":"bash","label":"npm"},{"cmd":"yarn add ts2nim","lang":"bash","label":"yarn"},{"cmd":"pnpm add ts2nim","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM default import. CommonJS require works: const ts2nim = require('ts2nim').","wrong":"","symbol":"default","correct":"import ts2nim from 'ts2nim'"},{"note":"CLI entry point can also be invoked via npx ts2nim.","wrong":"","symbol":"CLI","correct":"import { cli } from 'ts2nim'"},{"note":"TypeScript types are shipped with the package.","wrong":"","symbol":"Type","correct":"import type { TranspileOptions } from 'ts2nim'"}],"quickstart":{"code":"import ts2nim from 'ts2nim';\nimport { readFileSync, writeFileSync } from 'fs';\n\nconst typescriptCode = `\nfunction greet(name: string): string {\n  return 'Hello, ' + name;\n}\n`;\n\nts2nim.transpile(typescriptCode, { mode: 'source' }).then(result => {\n  writeFileSync('greet.nim', result.output);\n  console.log('Transpiled successfully');\n});","lang":"typescript","description":"Demonstrates programmatic usage: transpile a simple TypeScript function to Nim using the default API."},"warnings":[{"fix":"Manually import and translate required modules, or use .d.ts files for wrapper generation.","message":"The transpiler does not resolve external dependencies; it only translates the given source files.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Manually adjust number types in generated Nim code.","message":"Type inference for native types (e.g., number as int vs float) is not yet implemented; all numbers become float.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Refactor TypeScript classes to avoid multiple inheritance, or use composition instead.","message":"Multiple inheritance from TypeScript classes is not supported; Nim does not support multiple inheritance.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Review generated Nim code for rest parameters and adjust types as needed.","message":"Rest parameters in TypeScript become openArray[T] in Nim, which may require manual adjustment.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Add import asyncdispatch or import asyncjs to the top of generated Nim file.","message":"Async functions are translated with {.async.} pragma but require the asyncdispatch or asyncjs module to be imported manually.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run npm install ts2nim and use correct import: import ts2nim from 'ts2nim'.","cause":"The package is not installed, or the import path is incorrect.","error":"Error: Cannot find module 'ts2nim'"},{"fix":"Use import ts2nim from 'ts2nim' and call ts2nim.transpile().","cause":"Incorrect import; transpile is a method on the default export, not a named export.","error":"TypeError: ts2nim.transpile is not a function"},{"fix":"Manually review and fix the generated Nim code, especially around function signatures and type casts.","cause":"TypeScript type annotations are not fully removed or converted incorrectly for certain constructs.","error":"SyntaxError: Unexpected token ':' - expected '(' in Nim code"},{"fix":"In the CLI, use --declaration flag or set mode: 'declaration' in programmatic API.","cause":"Using .d.ts files requires mode set to 'declaration' or specific options.","error":"Error: TSMethodSignature not supported in current mode"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}