Readonly with Rob Meyer - TypeScript Type Challenges #7 [EASY]

preview_player
Показать описание
The ability to mark a field as readonly is one of the fundamental tools in the TypeScript toolbelt because it prevents users from mistakenly using a field that you don't want it to be possible to use.

00:00 description of the challenge
01:02 attempt at a solution
01:54 all tests pass
02:00 examining the actual TypeScript builtin
02:44 no alternatives known

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

I think it's also worth mentioning the "deep readonly" here, since it's pretty close to normal Readonly:

type DeepReadonly<T> = {
readonly [Property in keyof T]: T[Property] extends object
? MyReadonly<T[Property]>
: T[Property]

Lambdaphile
Автор

I'm wondering why would you not want to constraint T to extend object, to disallow something like MyReadonly<1>;?

LauriePoulter-km
Автор

nice. it would be really cool if you guys could explain or talk about index signatures more in-depth in a video or talk.

FunctionGermany