SharpTS 1.0.2
See the version list below for details.
dotnet tool install --global SharpTS --version 1.0.2
dotnet new tool-manifest
dotnet tool install --local SharpTS --version 1.0.2
#tool dotnet:?package=SharpTS&version=1.0.2
nuke :add-package SharpTS --version 1.0.2
SharpTS
A TypeScript interpreter and ahead-of-time compiler written in C#.
Overview
<img width="2816" height="1536" alt="Gemini_Generated_Image_go1ahqgo1ahqgo1a" src="https://github.com/user-attachments/assets/565d98dc-8268-4cd6-8b34-7cc24a0f7a4a" />
SharpTS is an educational implementation of a TypeScript interpreter and compiler. It demonstrates how programming languages work by implementing the complete pipeline from source code to execution:
- Lexical Analysis - Tokenizing source code
- Parsing - Building an Abstract Syntax Tree
- Type Checking - Static type validation
- Execution - Either interpretation or compilation to .NET IL
SharpTS supports two execution modes:
- Interpretation - Tree-walking execution for rapid development
- AOT Compilation - Compile TypeScript to native .NET assemblies
Features
Language Support
- Types:
string,number,boolean,null,any,void - Arrays: Typed arrays with
push,pop,map,filter,reduce,forEach, etc. - Objects: Object literals with structural typing
- Classes: Constructors, methods, fields, inheritance,
super, static members - Interfaces: Structural type checking (duck typing)
- Functions: First-class functions, arrow functions, closures, default parameters
- Control Flow:
if/else,while,do-while,for,for...of,switch - Error Handling:
try/catch/finally,throw - Operators:
??,?.,?:,instanceof,typeof, bitwise operators - Built-ins:
console.log,Mathobject, string methods
Compiler Features
- Static type checking with helpful error messages
- Nominal typing for classes, structural typing for interfaces
- Compile to standalone .NET executables
Quick Start
Prerequisites
- .NET 10.0 SDK or later
Installation
Install from NuGet (recommended):
dotnet tool install -g SharpTS
Or build from source:
git clone https://github.com/nickna/SharpTS.git
cd SharpTS
dotnet build
Usage
REPL Mode:
sharpts
Run a TypeScript file (interpreted):
sharpts script.ts
Compile to .NET assembly:
sharpts --compile script.ts
dotnet script.dll
Compile with custom output:
sharpts --compile script.ts -o myapp.dll
Examples
Hello World
// hello.ts
console.log("Hello, World!");
$ sharpts hello.ts
Hello, World!
Classes and Inheritance
// animals.ts
class Animal {
name: string;
constructor(name: string) {
this.name = name;
}
speak(): string {
return this.name + " makes a sound";
}
}
class Dog extends Animal {
speak(): string {
return this.name + " barks!";
}
}
let dog = new Dog("Rex");
console.log(dog.speak());
$ sharpts animals.ts
Rex barks!
Functional Programming
// functional.ts
let numbers: number[] = [1, 2, 3, 4, 5];
let doubled = numbers.map((n: number): number => n * 2);
let evens = numbers.filter((n: number): boolean => n % 2 == 0);
let sum = numbers.reduce((acc: number, n: number): number => acc + n, 0);
console.log(doubled); // [2, 4, 6, 8, 10]
console.log(evens); // [2, 4]
console.log(sum); // 15
Compiled Execution
# Compile to .NET assembly
$ sharpts --compile functional.ts
# Run the compiled assembly
$ dotnet functional.dll
[2, 4, 6, 8, 10]
[2, 4]
15
Documentation
- Architecture Guide - Deep dive into the compiler/interpreter internals
- Contributing Guide - How to contribute to the project
Project Status
SharpTS is under active development. See STATUS.md for current feature support and roadmap.
Looking for help with:
- Additional TypeScript features (generics, enums, modules)
- IL compiler feature parity
- Performance optimizations
- Test coverage
Contributing
Contributions are welcome! Please read our Contributing Guide for details on:
- Setting up your development environment
- Code style guidelines
- How to add new language features
- Submitting pull requests
License
This project is licensed under the MIT License - see the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.