In the README, it is said that ADT is expected to be similar to the tagged union type in TypeScript. However, the tagged union type is just plain objects in JavaScript and we can already use it nowadays, and the type system is built with TypeScript and there is nothing to do with JavaScript: TypeScript emits legit JavaScript codes and stripped type information in .js results.
It is also noted that the ADT is expected to work with pattern match well. However, I didn't find there is significant gain with ADT compared with the tagged union pattern on the pattern match with a new significant type introduction:
enum Message for function {
Quit,
Move { x, y },
Write(message),
}
const value = Message.Write('my message');
match (value) {
when MessageCreator.Write(message): ...
}
if (value.type === Message.Write) {
...
}
2. With the tagged union pattern: (copied from https://github.com/tc39/proposal-pattern-matching#code-samples)
```js
const Message = {
Write: 'write',
}
const value = { type: Message.Write, message: 'my message' };
match (value) {
when ({ type: Message.Write, message, ...rest }) {
handleMessage(message, rest);
}
else { throwSomething(); }
}
Comparing the above two examples, I didn't find significant benefits we gain from introducing a new "type" to the language. It will be helpful if the proposal can describe the concrete benefits of the new concept.
In the README, it is said that ADT is expected to be similar to the tagged union type in TypeScript. However, the tagged union type is just plain objects in JavaScript and we can already use it nowadays, and the type system is built with TypeScript and there is nothing to do with JavaScript: TypeScript emits legit JavaScript codes and stripped type information in .js results.
It is also noted that the ADT is expected to work with pattern match well. However, I didn't find there is significant gain with ADT compared with the tagged union pattern on the pattern match with a new significant type introduction:
const value = Message.Write('my message'); match (value) { when MessageCreator.Write(message): ... }
if (value.type === Message.Write) { ... }
Comparing the above two examples, I didn't find significant benefits we gain from introducing a new "type" to the language. It will be helpful if the proposal can describe the concrete benefits of the new concept.