-
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
Inconsistent behaviour of Pick<T, keyof T> for readonly attributes. #14295
Comments
Seems like there is no way to reset readonly modifier which is not very convenient const foo = {
bar: "baz",
}
const readonlyFoo = Object.freeze(foo);
const writableFoo = { ...readonlyFoo };
writableFoo.bar = "not a buz, but something else";
~~~ [ts] Cannot assign to 'bar' because it is a constant or a read-only property. |
@RyanCavanaugh will you please take a look at the problem? If I understand correctly it is an issue |
So, this is still a bug, right? But instead of there being no way to remove modifiers (which was addressed in TS2.8), there is now no way to preserve the |
i'm facing this issue as well. should this be filed as a separate bug? |
TypeScript Version: 2.2.1
Code
Typescript Playground
In Typescript
2.1.4
you could usePick<>
to remove thereadonly
modifier from all attributes of an interfaceT
by callingPick<T, keyof T>
. From 2.1.5 this (mostly) doesn't work anymore. "Mostly" because it does still work for readonly index signatures.Expected behavior:
I personally would prefer if there would be some way to make an object mutable analog to
Readonly<>
but at least the behaviour should be consistent.Actual behavior:
The behaviour is inconsistent.
Edit:
I bisected this and it seems like 33b5125 that types propagate modifiers when using
Pick<T, K>
which suggests that the behaviour of the index signature example is the bug.The text was updated successfully, but these errors were encountered: