Skip to content

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

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

Closed
mhegazy opened this issue Nov 28, 2016 · 1 comment
Closed

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

mhegazy opened this issue Nov 28, 2016 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@mhegazy
Copy link
Contributor

mhegazy commented Nov 28, 2016

type T = { a? : number, b: string };
var y: T;
var x: Readonly<T> = y; // Error: Property 'a' is optional
@mhegazy mhegazy added the Bug A bug in TypeScript label Nov 28, 2016
@mhegazy mhegazy added this to the TypeScript 2.1.3 milestone Nov 28, 2016
@mhegazy
Copy link
Contributor Author

mhegazy commented Nov 28, 2016

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

@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Nov 29, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

2 participants