Skip to content

Mapped object type ignores readonly  #39802

@lsdsjy

Description

@lsdsjy

TypeScript Version:
3.5, 4.0.0-beta

Search Terms:
mapped object type, readonly property, exclude, lookup type

Code

type MyOmit<T, K extends keyof T> = {
  [S in Exclude<keyof T, K>]: T[S]
}
declare const foo: MyOmit<{ readonly a: number, b: number }, 'b'>
foo.a = 1  // expects error but none

declare const foo2: Omit<{ readonly a: number, b: number }, 'b'>
foo2.a = 1  // error as expected

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions