Bug: DeepReadonly<T>
and DeepWritable<T>
are not exact inverses if T
is a type parameter
#369
Labels
DeepReadonly<T>
and DeepWritable<T>
are not exact inverses if T
is a type parameter
#369
Versions
typescript
5.0.4
ts-essentials
9.3.2
Repro Code
TypeScript Playground
https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBDAnmApnA3nAIilYBKKAhgCYQB2ANogDTa5gDqUwMRARpWgL5wBmUCCDgByGAGcAtCnHiU5GMCKVxIgLAAoTSRQBjSkSho+AV3K7FFOEdIAeACoA+ABQA3ZSZQAuenkKkKagdHAEofVwhgEm09AyN+MwtgKwB3FhgUYLcPb18mdI4uYLC4CKjNJFQ4fzIqRGZWQsynOABePJrAxFscPAa2TmbHRwrkNH7iQc664La8-qaehmmgpxGNU3NLcmtiEjTWIecoFJ8V+oLB4Lo0nwmm8+KMTThX3bsnY5SQl7eDjKyaR+Gm4miAA
Expected Result
DeepReadonly<DeepWritable<T>>
should be assignable toDeepReadonly<T>
andDeepWritable<DeepReadonly<T>>
should be assignable toDeepWritable<T>
.Actual Result
The above are not actually assignable if
T
depends on any type parameter (ifT
is fully concrete then it works as expected). It would be nice if this also works for type parameters.However, I am not sure if this is even possible in TypeScript (the type system might not be powerful enough, or that checking for such type equality with a free parameter is undecidable), and it might be more work than what it is worth.
A more practical workaround I am using right now is manually doing the conversion using a overloaded function, which you may be interested in:
The text was updated successfully, but these errors were encountered: