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
๐ข How to build a fully typesafe API with
@EffectTS_
and effect-http
- Request and Response validation and type checking
- Logging
- OpenTelemetry
- Auto generated OpenAPI
- Database
๐
๐ข Happy to announce that i'm now part of
@EffectTS_
open source team core members.
I'll help maintain the sql subset packages i contributed to.
I'd like to thank
@thefubhy
and
@MichaelArnaldi
and the rest of effect team for welcoming me in this amazing project.
@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
๐
๐ขI plan to do some
@EffectTS_
feedback in the coming weeks in the form of blog posts Effect/XXX vs YYY.
Examples:
- Effect/schema vs Zod
- Effect/rpc vs tRPC
Please propose some topics and i'll add them to my todo list๐
@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 :
To everyone asking "why not useRef?", the better question is: "why would you do it with useRef" ?
1) It doesn't have a lazy initializer function. So either you create new Resource() unnecessarily on every render, or you do an if (!resource.current) and initialize afterwards.
2)
๐ข 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
thinking about how much I wish React context was typesafe like Effect services
throwing in a useMyContext() hook may be type safe, but it's runtime anxiety-inducing. make sure I pass a provider at compile time before I run the app ๐ซ
@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 ๐งโโ๏ธ
๐ข 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
@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.
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'
๐ข Don't claim things without backup benchmarks.
@EffectTS_
is Fast
Simple test on Bun with sqlite db inserts + schema + logging
Using k6 for load testing.
Left : Elysia
Right: Effect
๐ข 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
๐ข If you haven't tried ollama, you should.
It's the swiss knife of open source LLMs.
Just do :
download > ollama pull llama3
test cli > ollama run llama3
serve > ollama serve llama3
.
@Meta
Llama 3 - The most capable openly available LLM to date!
ollama run llama3
If you have pull the llama 3 model prior to this post, please update the model using `ollama pull`.
Typesafe route modules achieved internally at
@remix_run
+ React Router v7 . All props (params, loader data, action data, etc.) all ๐ฏ% inferred.
If you ask me really nice, I might even share the TypeScript playground for you to try out soon ๐
@kentcdodds
Hi kent, try it before saying never. You were also skeptikall about Typescript.
I don't read a lot of informed judgment about people disliking it after using it.
Get your hands dirty and try it. Give us real feedback past just a gif impression.
For my previous example to be fully testable, we need to make DB access abtracted with a repository.
Here a fully testable version with a Repository Service added in context.
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):
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!
๐ข 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.
๐ข 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
@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
๐ 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.
๐กIdea:
What about an
#andventofeffect
tag where you solve
#adventofcode
with
@EffectTS_
library
Would be a great way to learn and promote Effect.
Last year i did it with generators, but hit a wall for complex ones where generators could not help.
I think Effect would scale
@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.
@EffectTS_
@thefubhy
@MichaelArnaldi
For my future contributions to the project,
More HTTP layer related work.
- uwebsockets for node platform
- Higher level REST layer and giving feedback from the experience i gathered by creating Zodios library
๐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 :
๐ข 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