trav

trav

@techsavvytravvy.com

sr software engineer @ crunchyroll 🦀🔪 @ crablang winning the fight against Big Outside™

4.8K followers832 following1.3K posts

this weekend i'll be joining some friends to stream episode 1 of a brand new d&d campaign called Glow in the Dark - it's an original story created by my best friend and dm with fantasy, scifi, and anime/manga influences. come hang out sunday @ 4pm ET! twitch.tv/ptmhshow

don't even need the deepEquals since the type will be narrowed by returning the FAIL symbol. so if it's not that, it should be our type

trav@techsavvytravvy.com

so one of things you can do in typescript is create type predicates that allow you to check if an input value is a specific type with return type `x is Foo`. unfortunately there is nothing that helps you make sure the predicate is accurate - as long as it returns a boolean it will pass

so one of things you can do in typescript is create type predicates that allow you to check if an input value is a specific type with return type `x is Foo`. unfortunately there is nothing that helps you make sure the predicate is accurate - as long as it returns a boolean it will pass

View full thread

the initial attempt is fine, but throwing then doing try/catch for each check isn't ideal and the predicate will be inferred for whatever type you return. instead i want the type param to be used explicitly and we'll return a symbol to indicate failure instead of throwing i think it's pretty nice!

i will say, there are some downsides. deepEqual can obviously get expensive if you're comparing a lot of big objects, and there are some dumb things about narrowing that mean you can't return the input directly

so one of things you can do in typescript is create type predicates that allow you to check if an input value is a specific type with return type `x is Foo`. unfortunately there is nothing that helps you make sure the predicate is accurate - as long as it returns a boolean it will pass

so a couple weeks ago i accepted an offer from crunchyroll for the Senior Software Engineer position on the video team and i start monday! and damn this snuck up on me i am not mentally prepared

really like this pattern where the type name is also the namespace name bc i don't have to do something like Result.Result that i see some others do with the `import * as Result` thing tree-shaking could be a concern tho idk