is a really well crafted website to learn advanced typescript.
It's 94 contributors... can't beleave so many ts wizards did it (lead by
@trashh_dev
).
A Masterpeace!
📢 Typescript tip for day 8 of
#AdventOfTypescript
1⃣ For those knowing about utility types, day 8 was easy. Just use Omit
🔗
2⃣ For those reinventing the wheel, you learned about Mapped Keys can also filter objects
@GregMolnar
Your chances to get a duplicate is 1 in the lifetime of the universe. And if you are concerned, roll your inserts in transactions so that they'll run again in case of failure.
UUID are good for distributed databases, for preventing predictable attacks, to allow parrallelism.
A lot of typescript wizards don't know this, but there is a way in typescript to do High Order Kinded Types:
@mattpocockuk
maybe a video about this would be cool
@dillon_mulroy
I would not say it's by the book. You have too much repetition allowing for errors everywhere.
Use your data as a single source of truth. Bonus, code is easier to read and maintain :
@JackEllis
The best advice i can give you is stop micro managing your team.
Do not review unless explicitly asked for.
Let your team review each other ones PR and give them your trust.
Even better, stop doing PRs and ask your team to do Peer programming.
Woops! Despite doing everything by the books and not using any escape hatches ('as', 'any', or 'non-null assertions') TypeScript let us give a normal 'member' admin permissions! 💥
📢 Typescript tip for day 9 of
#AdventOfTypescript
1⃣ You may have learned that typescript utility types can do recursion.
2⃣ recursion on types has a limit
3⃣ Solution : use Tail Recursion Optimisation
🔗
@trashh_dev
my rule of thumb :
- use functions for top level
- use arrow functions for anything else
This is also internal Deno rules, and in general i find that their style guide is really good :
📢 Typescript tip for day 12 of
#AdventOfTypescript
1⃣ Tuple['length'] is at the core of today's solution. It returns the length of a type Tuple
2⃣ First approach is to recusively search the Tuple from left to right
3⃣If you do the opposite, no need for an accumulator
📢 Typescript solution for day 17 of
#AdventOfTypescript
ℹ️ multiple ways to solve it. Chained conditionals, using a Lookup table...
1⃣ The hard part is that Rock Peper Scissors is that it's a cyclic graph
2⃣ You can generalize the problem to use a cyclic graph representation
@mattpocockuk
This comment with this other opened issue made me investigate typescript arcanes.
I was like "how the hell does this black magic works?"
Now that i understand it, i also do some vodoo 🧙♂️
@GregMolnar
It's not security by obscurity, you know the id perfectly well.
It's preventing certain type of attacks. Like creating a resource to gain knowledge about another.
Security by obscurity is a complete different beast.
📢 TypeScript TIP
ℹ️ You need to get unique strings from a tuple type of strings?
1⃣Here is an efficient way to do it in one pass by using a Map to check if the current element was already seen
What if you could store a global state at typelevel in typescript.
Thanks to interface and function overriding, you can🚀
You can check the real magic here :
📢 Hello Zodios users.
So last poll about zodios return type was a massive go for breaking change and return a complex object.
I also got feedback that throwing an exeption was still desirable behaviour.
So we will have best of both worlds like this :
Javascript arrays are not real arrays.
Meaning, it's not continuous memory, it's actually a linked list behind the scene. It's bad for performance.
If you need performance for some algorithms holding data, use Javascript derived ArrayBuffers structure:
📢 Typescript tip for day 11 of
#AdventOfTypescript
1⃣ Idea was to recusively mark properties readonly
2⃣ Functions get in the way, so you just need to check for it
3⃣ Tuples are Objects, so let typescript handle it
4⃣Typescript will bypass simple types like number, string
📢 Typescript solution for day 20 of
#AdventOfTypescript
ℹ️ Using HOTScript, it's looks like functional code, native solution coming later today
🔗 source code:
cc:
@TkDodo
since you tried using HOTScript
📢 Typescript solution for day 15 of
#AdventOfTypescript
ℹ️ This one was a good way to deeply understand how Distributed Conditionnal Types work.
1⃣ '(a | b) extends c ...' is the same as '(a extends c ...) | (b extends c ...)'
2⃣ Do 'Union extends T' and not 'T extends Union'
📢 I can finally define typeclasses with beautifull string literrals and it works! Fully typesafe, no codegen, it's just typescript.
🔗 Source code:
Here is a Monad !
📚 Zodios tip
You can use the exellent openapi to zodios playground
from
@astahmer_dev
It generates all the zod types and zodios api definition for you as if they where written by hand
🔗
It don't feel like generated code at all
#webdev
#typescript
📢 Typescript Solution for day 16 of
#AdventOfTypescript
ℹ️ Many possible solutions, with Object Maps or Tuple Recursion
1⃣ Here we show a solution involving Distributed Conditionnal Types, no recursion or Mapping
2⃣ We pre-compute all X and Y indexes to distribute over
📢 typematic has now support for JSON Schema with typescript inference out of the box
This means you can copy paste your open api schemas directly and have typescript infer the types
📢 Typescript solution for day 20 of
#AdventOfTypescript
ℹ️ Split the problem in 3. For next days it will be more like 5 or 6.
1⃣ create a merge utility 2 ascii art tuples
2⃣ handle merging ascii art for a single line recursively
3⃣ handle spliting lines recursively
Don't forget that D.Knuth created a ton of efficient algorithms in the 70s.
Here is Knuth-Morris-Pratt for searching a pattern in Uint8Array.
@deno_land
you should use this instead of O(n*m) algorithm in std/bytes.
This one is only O(n+m):
📢 Typescript solution for Day 21 of
#AdventOfTypescript
1⃣Since the challenge is becoming more and more difficult everyday i now also do a blog post
2⃣The solution will also shared on TypeHero after the challenge has finished
🔗 link to blog post :
@c_horobin
@BanJoeH
@mattpocockuk
Best solution i've seen. 🚀
I did not though about it even though i'm using something similar for the late challenges 😅
1⃣ key points, it's using unions as a way to iterate over the indexes without using Object Mapping
A little simplification.
OK, now that i have a proof of concept that one can use typescript type system to generate fully programmable typeclass signatures. Next step to do this. This will greatly simplify FP libraries creation!
@kerematam
@kadikraman
@redmonkez
interrestingly, using a cross browser testing, i get :
chrome: switch is 30% slower
edge: switch is 30% slower
firefox: switch is 70% slower
opera: switch is 30% slower
webkit: lookup is 10% slower
safari: lookup is 10% slower
📢 Typescript solution for day 19 of
#AdventOfTypescript
ℹ️ Two steps solution that take advantage of Typescript memoization
1⃣ Build a tuple containing the same Toy N times
2⃣ Use a cyclic graph and iterate over the Tuple of numbers and build current toy for each of them
📚 Zodios / Fetch / Axios Tip Time!
If you need to cancel a request, but have many different AbortControllers that can be triggered to cancel your request, you can use this nice helper to combine your signals :
@fabiospampinato
@_duncanhall
@lewisl9029
@oven_sh
This is plain wrong. He could build it by working 40h a week on it. Bun might even be better, because he would have more time to introspect.
Like kevlin henney says:
"you have to slowdown, that's how you go fast"
He is doing open source, there is no hurge to deliver sooner.
📈If you have an API that is slow but is idempotent, put a cache in front of it.
🖥️ Do not try to handle cache invalidation. It's too hard of a problem. you'll fail to handle every edge cases.
Here's my solution 👇
📚 Zodios Tip Time.
🛠️ You can create helpers to simplify API definition.
Should i include it in Zodios api helpers ? Would be specific to zod (not working for yup, io-ts, etc).
Here a zodToParameters example with
🔗 Playground link :
@housecor
You can iterate with TDD, in fact that's how it's done.
Red, Green, Refactor, Repeat.
In the Red phase, you can break your design
In the Green phase you can rewrite the tests
In the Refactor phase, you only rewrite the internals.
📢 I'm at minimum 6 month behind
@tannerlinsley
but this is cool 🤯
🚀 Typematic now detect duplicated endpoints or aliases at compile time and gives some tips to fix it.
📑 Example for duplicated endpoint (same method and path)
📢 Typescript solution for day 23 of
#AdventOfTypescript
ℹ️ This challenge was a lot like tic-tac-toe one, but with more dynamic checks and less union tricks since we really need to count the number of consecutive Chips.
🔗 Link to blog post
@ryanflorence
I can't disagree more.
Client side caching and data replication is what browser is doing since forever.
Round trip for api calls to server to get it from infrastructure cache still slower than taking data from browser memory with react-query.
10 µs vs 10→100ms network latency
Effect is is an underrated piece of engineering. The amount of crafting that goes inside so users don't have to worry is incredible.
And the code is so clean.
🚀 A masterpiece
📢 Typescript tip
Day 5: we saw Tuple concatenation
1⃣ Tuples are a powerfull way to ensure typesafety access in typescript
2⃣ If you know an array has a fixed number of items at compile time, prefer using Tuples to describe them
It's safer and garanty no out of bound access
Can we talk about why everyone is using regex to validate emails when emails are not parsable by a regex ?
Why nodejs or Browser api does not provide an email parser out of the box like they do for URL parser ?
If you know a good email validation lib, please comment.
I've completed Day Fourteen - Advent of TypeScript 2023
#AdventOfTypescript
⌛️A bit late today, was busy working
1⃣ The solution is to use recursive, no other way that i know of for strings
2⃣ Bonus, using type level regex from
@didavid61202
📢 Typescript solution for day 13 of
#AdventOfTypescript
ℹ️Using HotScript it's pretty straighforward by using number arithmetics
⏰ Later today i'll show a native solution without using HotScript
I think that tomorrow
#AdventOfTypescript
will be WTF all around.
Don't be surprised, i had to make you work for the badges, they cost a lot to
@trashh_dev
team to make.
But i believe you can do it!
📢 Typescript solution for day 18 of
#AdventOfTypescript
1⃣ We recusively add items to an accumulator when they match the searched items
2⃣ When they don't match we discard the item and continue with the Tail
ℹ️ Bonus, it can count many different items by just using unions
@t3dotgg
We are creating a lib of it, but it will be targeting heavy typescript library authors to make their typescript libraries easier to maintain (like zod, trpc, tanstack, zodios).
Users of those libs will just profit from it indirectly :
@GabrielVergnaud
This means you can now implement a parse safe implementation like
@arktypeio
in just a few lines of code.
Ideas:
- typesafe
@GraphQL
without code generation
- typesafe SQL based on your schemas
- typesafe router like
@tan_stack
router
it's endless
Zodios just got 800⭐️ on github. Thanks! 🙏
Adoption is also growing pretty fast and that's actually the most relevant metric to tell if it is actually usefull.
More Zodios status info 🧵👇
@ryanflorence
There are two aspects :
- show appreciation to the library author since there is a gihub trend feature based on stars
- have bookmark and notifications on updates on your "for you" tab :
Bun does esm/cjs right. It solves every issue we have with nodejs approach.
You can mix esm and cjs import styles in the same file, bun don't care, it just works! 🚀
@nodejs
now you know what to do.
Way to go
@jarredsumner
and congrats on 1.0 release.
I dwelved in this problem a lot.
Error codes are not the only information you can return
There is Status text and also HTTP json body
If you are concerned about Analytics you can also add tags to your Open Telemetry Spans to distinguish them in your dashboards
The inconvenience of REST is that you get a 404 error regardless of whether the URL is wrong or the correct URL is called, but the resource does not exist. How do you handle that?
I know TS team is discouraging this.
But since there are multiples uses cases where you actually need it.
Here yet another an example of where object keys to tuple is needed and key order is not an issue.
With this post I publish my bachelor thesis. 🧑🎓 As part of the research I looked at
@zodtypes
,
@arktypeio
and Typia and investigated how the bundle size of JavaScript libraries can be reduced. Thank you
@mhevery
and
@RyanCarniato
for your support.