4 ms·
The TypeScript EvenList<T> type at the end does not work as the author is implying. https://www.typescriptlang.org/play?#code/C4TwDgpgBAogbhAdgGQJYGdgB4AqA+KAX
by city41 6y ago
The TypeScript EvenList<T> type at the end does not work as the author is implying.
https://www.typescriptlang.org/play?#code/C4TwDgpgBAogbhAdgGQJYGdgB4AqA+KAXigG0BdKAH1JwBoo7YEUNt8yBuAKC4GMB7RJigAjAFxMkaTFkQBXALYiIAJwLESARloAmTn0HCAhhPhTWsxcrVFS2nbQDMtACz6gA https://www.typescriptlang.org/play?#code/C4TwDgpgBAogbhAdgG...
I am not a TS type expert by any means, but I don't believe it's possible to express an even list in TS's type system.
But with that said, I enjoyed the article and I agree with the points its making.
- lexi-lambda 6y agoI (the author) did not imply that the definition of EvenList I gave would admit [1, 2, 3, 4]—it only admits [1, 2, [3, 4, []]]. Indeed, this is the whole point of the second half of the blog post: you can enforce lots of invariants by modifying the way you represent your data, at the cost of having to write some additional code to work with your alternative representation. Reread the conclusion.
- city41 6y agoYup, my bad. Thanks for poking me.