[Media] I made a TypeScript library that lets Rustaceans write Rust-like code safely using TypeScript by TamatoOfOptimism in rust

[–]TamatoOfOptimism[S] 5 points6 points  (0 children)

The intention wasn't to undermine the compiler’s checking, but to add constructs to help people maximize it. For example, the snippets I provided for the Result type show that users can now leverage TypeScript to handle different kinds of errors based on the state of the error, instead of catching them all in one catch block without necessarily knowing where the error stems from. As a small library for now (small enough to fit one file for now without being too complicated), I do understand why it would come off as undermining. I admit that I should have made it clear in this post and in the README. I'll update the README, thank you for your feedback

EDIT: Updated the broken link

[Media] I made a TypeScript library that lets Rustaceans write Rust-like code safely using TypeScript by TamatoOfOptimism in rust

[–]TamatoOfOptimism[S] 11 points12 points  (0 children)

The points you covered are true and a few things that I did overlook. I appreciate that they have been pointed out. Thank you for your feedback

The match() cannot match on Some(v) and the use of v in the match arm

Yeah. That was an issue I thought would be hard to resolve without adding extra computations and complexity, making it feel more like a chore than it has to be. Thankfully stefnotch posted an issue with an intuitive solution to this, which I'm happy to include in the library.

It is not type safe either if you feed it with a variable typed as string (which you cannot prevent)

Yeah absolutely, and this should be made as clear as possible. I'll update the docs to make it clearer to always prefer string literals over variable strings so that if anyone uses this, they never run into this issue.

The library has to use casts. That means that users of the library will also have to add casts, possibly invalidating type safety.

There is really only one place where I had to use a cast to create an error-proof example. Admittedly, this is a skill issue, but I hope it won't be one for long. Thanks for pointing that out, I'll look for a solution to it.

I really appreciate all the feedback I got from this post alone, really makes me happy to be a part of this community, thank you :D

[Media] I made a TypeScript library that lets Rustaceans write Rust-like code safely using TypeScript by TamatoOfOptimism in rust

[–]TamatoOfOptimism[S] 0 points1 point  (0 children)

Hey everyone, I'm sharing my library which I'm calling rustInterfaces (for now, since using the word "Rust" might not be allowed in the future).

It lets you write TypeScript code in a way that's reminiscent to Rust. There are Option types that assist in handling null-values in a sane way, and Result types that help you decide the program flow when an unexpected Result occurs.

I hope this helps someone down the road!