-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Mapped Types syntax to remove modifiers #13723
Comments
I do not think we will be adding yet another construct to remove You can do this today by breaking the homomorphic relationship between the target of the map and the result; to do so you need to disassociate the key from the type. e.g.: type Mutable<T extends { [x: string]: any }, K extends string> = {
[P in K]: T[P];
}
type Mock<T> = Mutable<T, keyof T>; |
@mhegazy your code example is a solution if you want to transform interface TypeA {
readonly name: string;
} to interface TypeB {
name: string;
} But if you have interface TypeA {
readonly name: string;
readonly color?: string;
} and this would transform it to this interface TypeB {
name: string;
color: string;
} which is more then just removing the modifiers. In combination with |
No; we will need to add a new |
I think this was fixed by #21919. |
It definitely appears that way. The following works for me: type Mutable<T> = {
-readonly [P in keyof T]: T[P];
}; |
What if I want to remove the "private" keyword? |
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
Expected behavior:
type MyMockedType to be
Actual behavior:
not possible right now
The text was updated successfully, but these errors were encountered: