EkScript is very, very similar to TypeScript. It has the same NodeJS APIs for server-side programming.
WORK-IN-PROGRESS
A few number types have been introduced in EkScript.
Character type: char
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!
// --- β ERROR! TS Only β ---βlet a = null; // βNo Type declaration hereβlet b: string = 'Hello' ;b = null; // βNon-nullable typeβlet c = { hello: 'world' };c.hello = null;βlet d: undefined; // ERROR! No type named as undefinedβif (a) {} // β a is not booleanif (!!c.hello) {} // β a is not booleanβ// --- β VALID! Eks β ---let d: string? = 'Hello';d = null; // nullable typeβif (d == null) {}βlet a = 0;if (a == 0) {}βtype TC = { hello: string?, key: i32 }; // [key: string] : i32let c = { hello: 'world' };c.hello = null; // nullable fieldsβfunction fn(a: object) {console.log(a?.hello); // null
Yes. No more '==' and '===' confusion. Simply write '==' everywhere.
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!
// --- β ERROR! β ---Number.prototype.toExponential.call(1);function f() {this.hello = 1;this.world = 2}f.prototype.hello = 3;this.hello = 'there';
There are two additions to EkScript. First is its pattern matcher which takes types as first class citizens:
const variable: string | int = 1;βmatch(variable)(int => console.log("int found"),string => console.log(""))
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)
// --- β VALID! β ---if (typeof a == int) {console.log("int found");} else if (typeof b == string) {console.log("string found")}β// --- ERROR! β ---typeof typeof int; // cannot use it outside a binary expression
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.
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.
type THello = { hello: string }β// --- β VALID! β ---const var1 = EKON.parse<THello>('{ "hello": "world" }');const var2: EKONObject = JSON.parse('{ "hello": "world" }');const var3 = JSON.parse('{ "hello": "world" }'); // inferred as EKONObjectβ// --- ERROR! β ---const var3 = JSON.parse('{ "hello": "world" }');someRandomFunc(JSON.parse('{ "hello": "world" }'));