Feature | TypeScript | Nim |
---|---|---|
Execution model | JavaScript code (Compiler) | JavaScript code (Compiler) |
Written using | TypeScript | Nim |
License | Apache | MIT |
Version (Mayor) | 3.x |
1.x |
Typing | Static | Static |
Meta-programming | ❎ #issue-13252, Decorators are limited | ✔️ template, macro |
int8/16/32/64 types | ❎ | ✔️ |
float32/float64 types | ❎ | ✔️ |
Char types | ❎ | ✔️ |
Subrange types | ❎ #issue-225324972 | ✔️ |
JSON types | ❎ #issue-56296923 | ✔️ |
Regex types | ❎ #issue-128264906 | ✔️ |
Option types | ❎ | ✔️ |
Dependent types | ❎ | ✔️ |
Operator Overloading | ❎ | ✔️ |
Custom Operators | ❎ | ✔️ |
Enum types | ✔️ | ✔️ |
Immutability | Limited, readonly keyword |
✔️ |
Function Arguments Immutability | Mutable | Immutable |
Full DOM API | ✔️ | ✔️ |
NodeJS integration | ✔️ | ✔️ |
Generics | ✔️ | ✔️ |
Type inference | ✔️ | ✔️ |
Closures | ✔️ | ✔️ |
Object-Oriented | ✔️ | ✔️ |
Methods | ✔️ | ✔️ |
Exceptions | ✔️ | ✔️ |
Anonymous Functions | ✔️ | ✔️ |
Arrow Functions | ✔️ | ✔️ |
Array Comprehensions | ✔️ | ✔️ |
Formatted String Literals | ✔️ | ✔️ |
FFI | ✔️ JS only | ✔️ C/C++/JS |
Async | ✔️ | ✔️ |
Regex | ✔️ | ✔️ |
Self-Documentation comments | ✔️ | ✔️ |
Package Publishing | ✔️ | ✔️ |
Package Manager | ✔️ | ✔️ |
Code AutoFormatter | ✔️ via NPM | ✔️ Nimpretty |
Syntax similar to | JavaScript | CoffeeScript or Python |
Variables
Creating a new variable uses var
or let
or const
.
Nim has immutability and compile-time function execution.
You can assign functions to variables.
-
const
is different from TypeScript by being truly immutable.
Declaration | Compile-Time | Run-Time | Immutable | Requires Assignment |
---|---|---|---|---|
var |
❎ | ✔️ | ❎ | ❎ |
let |
❎ | ✔️ | ✔️ | ✔️ |
const |
✔️ | ❎ | ✔️ | ✔️ |
Compile-Time Function Execution
Nim has Compile-Time Function Execution that allows you to run Backend-like code at compile-time and use it on Frontend at run-time.
Compile-time FFI is also possible, you can pull data from C/C++ libs at compile-time and use it on Frontend at run-time.
Most code that works at compile-time and NimScript also tends to work for Frontend.
Example: Compile-time recursive file system walk module.
Svelte
Nim has some similarities with Svelte for Frontend, but at the time of writing Svelte does not fully supports TypeScript.
Svelte can not do Backend (is not designed to).
Build Modes
Feature | Release Build | Debug Build |
---|---|---|
Speed | Fast | Slow |
File Size | Small | Big |
Optimized | ✔️ | ❎ |
Tracebacks | ❎ | ✔️ |
Run-time checks | ❎ | ✔️ |
Compile-time checks | ✔️ | ✔️ |
assert |
❎ | ✔️ |
doAssert |
✔️ | ✔️ |
- Once compiled it wont need Nim anymore, 100% dependency-free.
Hello World
echo "Hello World"
Console Hello World:
console.log("Hello World")
Thank you for playing
There's bridged Gitter, Matrix, Telegram, IRC, Discord for Nim, come say Hi.
Nim Homepage
Learn Nim today.
Grupo de Telegram en Español.
👑
Top comments (0)