Is '+readonly' really legal?! - Type Challenges #2

preview_player
Показать описание
Become a TypeScript Wizard with Matt's upcoming TypeScript Course:

Follow Matt on Twitter

Take the challenge:

Рекомендации по теме
Комментарии
Автор

These are enlightening shorts. Thanks Sir, for sharing you knowledge.

jonathangeorge
Автор

Great job Matt. Please complete all of those type challenges. Don't stooppp!!

osmangonichowdhury
Автор

Is there a benefit in checking the exit point of the recursion - typeof T[K] extends never ?.... rather than what you did which evaluates ....T[K] extends object ?....WTUT?

talfaran
Автор

Youtube algorithm brought me here, and I have no clue what the hell is going on :D

Good video I guess ;)

dalius
Автор

your tutorials are really helpfull | thanks for your effort

rahimco-susc
Автор

Perhaps this is a super dumb question, but here it goes.

I have been adding readonly to every key of object, and this method of using mapped key looks like a game changer to me.

Is there any ‘other’ difference between the two methods besides removing the redundancy of writing ‘readonly’?

By the way, all of your short videos are really broadening my insight of typescript. Thank you so much!

gaddp
Автор

Can you do video for angular's new strictly typed reactive forms ? ... I am facing issue to convert an existing interface into a type for formgroup.. I hope you will reply !

balajibalamurugan
Автор

So when you do this ‚blabla‘ value thingy - that means every object I assign this type to will get it’s value overwritten with ‚blabla‘ ( probably only the type of the object will make it look that way? Right?)

florianneumann
Автор

Thanks for sharing. My wish is to press the like button 1 million more times.

esmaeilmirzaee
Автор

Great video as always.
I apologize for misusing the video comments but I was wondering if you could give me some tips for using the zod library. Although zod has a great type inference from zod 'definition' I'm actually generating zod objects for existing typescript objects and I would just like to assert that the zod inference would generate the same ts type as already exists. For now I'm using following syntax:
const schema: z.ZodSchema<{id: string}> = z.object({id: z.string().min(1)});

This works but the type cast is slicing of the full z.object ('id' field is missing etc). Any tips?

Автор

Amazing vid!! I was literally today wondering how I could read only all my properties at once 😂😂😂

Also what the heck is that + - wizardry?

Have you seen the TS docs? why are they so

angelo
Автор

It's very rarely that I need ReadOnly..
I usually end up with doing a
```ts
type MyReadonly<T, K extends keyof T> = Omit<T, K> & Readonly<Pick<T, K>>;
type A = {
a: string,
b: string,
}
type B = MyReadonly<A, 'b'>;
const c: B = {
a: 'hello',
b: 'goodbye',
}
c.b = 'seeya'; // Error: Cannot assign to 'b' because it is a read-only property
```

The only problem I get is the horrible looking output of the "type" I wish I knew a way to "flatten it" in the IDE hint system from `type B = Omit<A, "b"> & Readonly<Pick<A, "b">>` to `{ a: string; b: readonly string; }`

ColinRichardson
Автор

Horrendous inline generics again! Where a single Letter would do..

ColinRichardson