-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Mapped object type ignores readonly #39802
Comments
This is working as intended.
type MyOmit<T, K extends keyof T, X extends keyof T = Exclude<keyof T, K>> = {
[S in X]: T[S]
}; You might be getting tripped up by #34793, since the IntelliSense for |
Seems work as your expected (If Pick Exclude). |
As far as I know, there are two ways to get a homomorphic mapped type. The normal way is to explicitly write type Homomorphic<T> = {[P in keyof T]: string}; The less common way is to write type PartiallyHomomorphic<T, K extends keyof T> = {[P in K]: string}; |
@jcalz Well, so in the |
TypeScript Version:
3.5, 4.0.0-beta
Search Terms:
mapped object type, readonly property, exclude, lookup type
Code
Expected behavior:
Assignment to
foo.a
is an error.Actual behavior:
No typing error reported.
Playground Link:
https://www.typescriptlang.org/play/index.html?ts=4.0.0-dev.20200729#code/C4TwDgpgBAsiDyBbAlsAPAFQDRQNJQgA9gIA7AEwGcoBrCEAewDMoMA+KAXigG8AoKFADaAZSjJSUAKKEAxgBsAruQho6jFtjxsAugC5WonXwC+fFQoCGAJ2iyGpSsChMGDA3CSo0PKLcvkDvIgUJYGpIqIAEYQ1jhR4ZEx1lAmOADkUelsfK4MAHSWXFAAjIIA9OUEhJCywNSx1gwpUYrOpA4QfOYQVrZQ9o7OeQBMBl7ovv6BpMGhidGx8QvJqRlZOaOFxWVQlQTWTSmWDTW9JORAA
Related Issues:
The text was updated successfully, but these errors were encountered: