Skip to content

Readonly type breaks Set and Map #29655

@falsandtru

Description

@falsandtru

TypeScript Version: 3.4.0-dev.201xxxxx

Search Terms:

Code

// A *self-contained* demonstration of the problem follows...
// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.

Expected behavior:

However, Set and Map can't use with es3 and es5. We need any workaround.

export type Readonly<T> =
  T extends ReadonlySet<infer V> ? ReadonlySet<V> :
  T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<K, V> :
  { readonly [P in keyof T]: T[P]; };

Actual behavior:

type Readonly<T> = {
    readonly [P in keyof T]: T[P];
};

Playground Link:

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions