Skip to content

Variable with advanced type with optional property can be assigned simple type value #17843

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
hoegge opened this issue Aug 16, 2017 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@hoegge
Copy link

hoegge commented Aug 16, 2017

TypeScript Version: TSLint 2.4.0 in VSCode and www.typescriplang.org playground today (2017-08-16)

Code

let a: { property?: string } = 1234; // why is this allowed?

Expected behavior:
It should not be possible to assign a number to a variable a of type { property?: string } or ... { property?: string | undefined; } if strict-null-check is turned on.

Actual behavior:
a is assigned the value 1234
If the type's property is not optional, it behaves as expected, i.e. type { property: string }.

@DanielRosenwasser
Copy link
Member

Duplicate of #16333. Should be fixed in TypeScript 2.4.2.

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Aug 16, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants