Skip to content

Readonly<T> not assignable to T with optional properties #12542

Closed

Description

type T = { a? : number, b: string };
var y: T;
var x: Readonly<T> = y; // Error: Property 'a' is optional

Activity

  1. added this to the milestone on Nov 28, 2016
  2. mhegazy commented on Nov 28, 2016

    @mhegazy
    ContributorAuthor

    Some other related examples:

    type T = { a? : number, b: string };
    var y: T = {} as any;
    var x1: Readonly<T> = y; // Error: Property 'a' is optional
    var x2: Partial<Readonly<T>> = y; 
    var x3: Readonly<Partial<T>> = y; // Error: Property 'a' is optional
    var x4: Partial<T> = y;
    var x5: Pick<T, "a"> = y; // Error: Property 'a' is optional
  3. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions