Ekscript for TS Devs
Know TypeScript? It will take about 5 minutes to get to know what is πŸš€
EkScript is very, very similar to TypeScript. It has the same NodeJS APIs for server-side programming.

Love Videos
πŸ“½
?

WORK-IN-PROGRESS

Language specification

​

New Types

A few number types have been introduced in EkScript.

int, float

Character type: char

No `any`, `undefined`, `unknown`, `never`, `NaN` and false-y values

To maintain a consistent strict code style, EkScript bars you from using any , undefined , unknown , NaN and never .null is to be used everywhere wherever previously you used undefined. This brings us to the concept of nullable and non-nullable types. Types that might have a null value or might not.
There are only two false-y values. That means if statements only take boolean and numbers for processing (ruby like). This also means that ! unary operator is only for boolean types and number types. Yes, you have to write more code but this will save time in the long run!
1
// --- ❌ ERROR! TS Only ❌ ---
2
​
3
let a = null; // ❌No Type declaration here
4
​
5
let b: string = 'Hello' ;
6
b = null; // ❌Non-nullable type
7
​
8
let c = { hello: 'world' };
9
c.hello = null;
10
​
11
let d: undefined; // ERROR! No type named as undefined
12
​
13
if (a) {} // ❌ a is not boolean
14
if (!!c.hello) {} // ❌ a is not boolean
15
​
16
// --- βœ… VALID! Eks βœ… ---
17
let d: string? = 'Hello';
18
d = null; // nullable type
19
​
20
if (d == null) {}
21
​
22
let a = 0;
23
if (a == 0) {}
24
​
25
type TC = { hello: string?, key: i32 }; // [key: string] : i32
26
let c = { hello: 'world' };
27
c.hello = null; // nullable fields
28
​
29
function fn(a: object) {
30
console.log(a?.hello); // null
Copied!

Extra Additions + Improvements

No more `===`!

Yes. No more '==' and '===' confusion. Simply write '==' everywhere.

No Prototype, different `this`!

No more 2 ways of defining classes. EkScript is a modern language. It only supports ECMAScript classes. Everything about classes is similar to TypeScript!
This also means that this is no longer relevant in functions! Only in classes, this is supported. Finally!
1
// --- ❌ ERROR! ❌ ---
2
Number.prototype.toExponential.call(1);
3
function f() {
4
this.hello = 1;
5
this.world = 2
6
}
7
f.prototype.hello = 3;
8
this.hello = 'there';
Copied!

Pattern Matching

There are two additions to EkScript. First is its pattern matcher which takes types as first class citizens:
1
const variable: string | int = 1;
2
​
3
match(variable)(
4
int => console.log("int found"),
5
string => console.log("")
6
)
Copied!

Improved typeof operator

Since we have types as first class citizens, EkScript provides a way to check types using simple `typeof` operator.
NOTE: This can only be used with certain binary operators and should be explicitly declared. (More on that later)
1
// --- βœ… VALID! βœ… ---
2
if (typeof a == int) {
3
console.log("int found");
4
} else if (typeof b == string) {
5
console.log("string found")
6
}
7
​
8
// --- ERROR! ❌ ---
9
typeof typeof int; // cannot use it outside a binary expression
Copied!

Browser DOM APIs

EkScript comes with libDOM.d.ek which is similar to libDOM.d.ts with a more strict API. TypeScript programmers won't even have to sweat on EkScript.

JSON + EKON

In TypeScript, JSON.parse returns any type. EkScript doesn't have any. Instead it takes a generic type that will be inferred at runtime giving you type-safety. EkScript ships with EKON instead of JSON. EKON is a superset of JSON and is quite excellent as a message passing or configuration file.
1
type THello = { hello: string }
2
​
3
// --- βœ… VALID! βœ… ---
4
const var1 = EKON.parse<THello>('{ "hello": "world" }');
5
const var2: EKONObject = JSON.parse('{ "hello": "world" }');
6
const var3 = JSON.parse('{ "hello": "world" }'); // inferred as EKONObject
7
​
8
// --- ERROR! ❌ ---
9
const var3 = JSON.parse('{ "hello": "world" }');
10
someRandomFunc(JSON.parse('{ "hello": "world" }'));
Copied!
Last modified 6mo ago