String untagged unions (value types) are currently supported by Derw, e.g type Fish = "Salmon" | "Trout". I will most likely add some way of handling types composed of other types, too.
That's cool. I am continuously tempted to do something similar like derw, but it would just be a distraction from my goal. On top of my daily todo list is the following sentence: FUCKING STAY WITH TYPESCRIPT, as a reminder to myself not to look for better solutions, or even create a better solution myself, because I just don't have the bandwidth.
But if you are going for it, that is great. Here are some features I would love for a language like derw. This is just meant to be a source of ideas you may or may not have thought of already, and obviously, your goals probably differ from mine:
1. Optimised arithmetic for 32-bit integer types int and uint.
2. Tagged unions based on uint, compiling to "const enum".
3. Provide an out-of-the box ! operator that actually throws an exception if the value is null or undefined.
4. Support for both mutable and immutable data structures out of the box.
5. Support for building reliable APIs, that cannot be breached even at runtime through some meddling JavaScript code. Currently I use Object.freeze all over the place, just to make sure that people cannot change randomly a class definition from right under me, etc. For example I have a decorator @fixed that is defined as
export function freeze<V>(x : V) : V {
if (typeof x === "function") {
Object.freeze(x.prototype);
Object.freeze(x);
} else {
Object.freeze(x);
}
return x;
}
freeze(freeze);
export function fixed<T extends { new (...args: any[]): object }>(target: T): T {
return freeze(class Final extends target {
constructor(...args: any[]) {
if (new.target !== Final) {
throw new Error('Cannot inherit from immutable class');
}
super(...args);
freeze(this);
}
});
}
freeze(fixed);
But if you are going for it, that is great. Here are some features I would love for a language like derw. This is just meant to be a source of ideas you may or may not have thought of already, and obviously, your goals probably differ from mine:
1. Optimised arithmetic for 32-bit integer types int and uint.
2. Tagged unions based on uint, compiling to "const enum".
3. Provide an out-of-the box ! operator that actually throws an exception if the value is null or undefined.
4. Support for both mutable and immutable data structures out of the box.
5. Support for building reliable APIs, that cannot be breached even at runtime through some meddling JavaScript code. Currently I use Object.freeze all over the place, just to make sure that people cannot change randomly a class definition from right under me, etc. For example I have a decorator @fixed that is defined as