Apparently it's the inferring the array type and passing it back to the Array generic that messes up the case for tuples. Turns out this step can be avoided by passing the property type directly, then the generic gets even smaller:
Array
type DeepReadonly<T> = Readonly<{ [K in keyof T]: T[K] extends (number | string | symbol) ? Readonly<T[K]> : Readonly<DeepReadonly<T[K]>>; }>
Here's the playground with the tuple example you provided.
I don't get, what's the benefit over this simpler variant?
type DeepReadonly<T> = { readonly [K in keyof T]: DeepReadonly<T[K]>; };
I don't see any apparent advantages, this one seems less verbose 🤔
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Apparently it's the inferring the array type and passing it back to the
Arraygeneric that messes up the case for tuples. Turns out this step can be avoided by passing the property type directly, then the generic gets even smaller:Here's the playground with the tuple example you provided.
I don't get, what's the benefit over this simpler variant?
I don't see any apparent advantages, this one seems less verbose 🤔