Closed
Description
Current TypeScript Version: 2.1.1
We have a syntax to add "readonly" to every property of a type. Unfortunately, it seems there is no way to have the reverse operation: removing it.
This is useful for creating Mocked version of types for UTs, which have readonly fields in production.
This should work recursively.
Code
interface MyType2 {
readonly z1: number;
z2: string;
}
interface MyType {
readonly a: number;
readonly b: MyType2;
c: string;
d: MyType2;
}
type Mock<T> {
[P in keyofwithoutmodifiers T]: Mock<T[P]>;
}
type MyMockedType = Mock<MyType>;
Expected behavior:
type MyMockedType to be
{
a: number;
b: { z1: number; z2: string };
c: string;
d: { z1: number; z2: string };
}
Actual behavior:
not possible right now