trav
banner
techsavvytravvy.com
trav
@techsavvytravvy.com
sr software engineer @ crunchyroll
🦀🔪 @ crablang
winning the fight against Big Outside™
2024 hellthread heavyweight champion

gas station snack enthusiast, father of some, does leetcode problems hardest to easiest, never sleeps, sometimes streams
lol it's always this
March 10, 2025 at 5:53 PM
started reading this to my 4yo tonight and she's about it
February 22, 2025 at 3:38 AM
💜
February 21, 2025 at 4:32 AM
no the function would return true, causing it to incorrectly be of type 'number' after narrowing with if statement
February 1, 2025 at 1:48 AM
no because it is narrowing it down to the type and only the specified type or the FAIL unique symbol can be returned, otherwise you'll get an error

you could of course return some literal value matching the type but that would have to be pretty deliberate
February 1, 2025 at 1:11 AM
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
January 31, 2025 at 11:42 PM
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
January 31, 2025 at 11:09 PM
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!
January 31, 2025 at 10:59 PM
so today @shreyascodes.tech had the idea to create an abstraction for predicate functions, and this is what i came up with initially. it works
January 31, 2025 at 10:59 PM
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
January 31, 2025 at 10:59 PM
can see it better here
January 31, 2025 at 2:36 AM
lissajous.ts
January 31, 2025 at 2:09 AM
January 30, 2025 at 5:53 AM
really? i find that usually when it comes to i/o and async ops that my python requires more ceremony and is harder to follow than the equivalent js
January 29, 2025 at 9:06 PM
oh it's nothing special just a wrapper around the defaults. can be overridden
January 29, 2025 at 7:27 AM
ehhh not really, just that a function is dynamically passed to the parent as an argument
January 29, 2025 at 4:45 AM
January 29, 2025 at 4:25 AM
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
January 29, 2025 at 4:08 AM
crazy i was just looking for this right when you posted
December 7, 2024 at 1:02 AM
I KNEW IT

more Big Outside™ propaganda
November 30, 2024 at 4:26 PM
oh i guess we're doing winter now
November 29, 2024 at 7:15 PM
November 27, 2024 at 3:40 PM
oh no
November 27, 2024 at 3:18 PM
i always forget you can scope types in typescript just like you can scope variables
November 26, 2024 at 6:44 PM
it's gonna be fine
November 26, 2024 at 2:38 PM