| Crates.io | TypeScript-Rust-Compiler |
| lib.rs | TypeScript-Rust-Compiler |
| version | 0.4.0 |
| created_at | 2025-09-28 10:57:07.970132+00 |
| updated_at | 2025-09-29 16:50:13.317779+00 |
| description | High-performance TypeScript to Rust compiler |
| homepage | |
| repository | https://github.com/FrankFMY/TypeScript-Rust-Compiler |
| max_upload_size | |
| id | 1858237 |
| size | 318,991 |
A TypeScript to Rust compiler that transforms TypeScript code into idiomatic, efficient Rust code with growing TypeScript feature support.
This project aims to create a high-performance compiler that can translate TypeScript code into safe, efficient Rust code while preserving TypeScript's type system and semantics.
let, const, var with type annotationsstring, number, boolean, null, undefinednumber[], Array<string>, readonly arraysexport declarations are parsedextends and implements clauses need more work# Install from crates.io
cargo install TypeScript-Rust-Compiler
# Or build from source
git clone https://github.com/FrankFMY/TypeScript-Rust-Compiler.git
cd TypeScript-Rust-Compiler
cargo build --release
# Compile a single TypeScript file
cargo run -- --input input.ts --output output.rs
# Compile with optimization
cargo run -- --input input.ts --output output.rs --optimize
# Compile with runtime support
cargo run -- --input input.ts --output output.rs --runtime
# Compile an entire project
cargo run -- --input src/ --output rust-project/
# Enable debug mode for detailed output
cargo run -- --input input.ts --output output.rs --debug
TypeScript Input:
interface User {
name: string;
age: number;
}
class Person {
name: string;
age: number;
constructor(name: string, age: number) {
this.name = name;
this.age = age;
}
greet(): string {
return `Hello, I'm ${this.name}`;
}
}
function add(a: number, b: number): number {
return a + b;
}
const result = add(5, 3);
Generated Rust Output:
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Person {
pub name: String,
pub age: f64,
}
impl Person {
pub fn new(name: String, age: f64) -> Self {
Self { name, age }
}
pub fn greet(&self) -> String {
format!("Hello, I'm {}", self.name)
}
}
pub fn add(a: f64, b: f64) -> f64 {
(a + b)
}
let result: f64 = add(5.0, 3.0);
| TypeScript | Rust |
|---|---|
string |
String |
number |
f64 |
boolean |
bool |
any |
Box<dyn Any> |
unknown |
Box<dyn Any> |
void |
() |
never |
! |
Array<T> |
Vec<T> |
Promise<T> |
Future<Output = T> |
Record<K, V> |
HashMap<K, V> |
interface Container<T> {
value: T;
getValue(): T;
setValue(value: T): void;
}
pub trait Container<T> {
fn get_value(&self) -> &T;
fn set_value(&mut self, value: T);
}
class Calculator {
private result: number = 0;
add(value: number): this {
this.result += value;
return this;
}
}
pub struct Calculator {
result: f64,
}
impl Calculator {
pub fn new() -> Self {
Self { result: 0.0 }
}
pub fn add(mut self, value: f64) -> Self {
self.result += value;
self
}
}
typescript-rust-compiler [OPTIONS] <INPUT> -o <OUTPUT>
OPTIONS:
-o, --output <OUTPUT> Output file or directory
-v, --verbose Enable verbose output
-d, --debug Enable debug mode
-O, --optimize Optimize generated code
-r, --runtime Enable runtime support
-h, --help Print help information
-V, --version Print version information
typescript-rust-compiler/
โโโ src/ # Source code
โ โโโ lexer.rs # Lexical analysis
โ โโโ parser.rs # Syntax analysis
โ โโโ ast.rs # AST structures
โ โโโ types.rs # Type system
โ โโโ generator.rs # Code generation
โ โโโ compiler.rs # Main compiler logic
โ โโโ main.rs # CLI entry point
โโโ examples/ # Example files organized by complexity
โ โโโ basic/ # โ
Fully working examples
โ โโโ advanced/ # โ ๏ธ Partially working examples
โ โโโ integration/ # ๐ Comprehensive tests
โ โโโ examples_outputs/ # Generated Rust files
โโโ tests/ # Unit and integration tests
โโโ docs/ # Documentation (planned)
# Run all tests
cargo test
# Run integration tests
cargo test --test integration_tests
# Run benchmarks
cargo bench
# Run with coverage
cargo test --features coverage
We welcome contributions! Please see our Contributing Guide for details.
git clone https://github.com/FrankFMY/TypeScript-Rust-Compiler.git
cd TypeScript-Rust-Compiler
cargo build
cargo test
# Test basic functionality
cargo run -- --input examples/basic/simple_test.ts --output examples_outputs/simple_test_output.rs
# Test interface generation
cargo run -- --input examples/advanced/separate_interface_test.ts --output examples_outputs/interface_output.rs
# Test comprehensive features
cargo run -- --input examples/integration/comprehensive_test.ts --output examples_outputs/comprehensive_output.rs
# Run all examples
bash examples/test_all.sh
Please report bugs on our Issue Tracker.
This project is licensed under the MIT License - see the LICENSE file for details.
extends and implements)Made with โค๏ธ by the TypeScript-Rust-Compiler team