Skip to content
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

TS should not allow assigning value with undefined union to non-nullable property when strictOptionalProperties #44437

Closed
HerringtonDarkholme opened this issue Jun 4, 2021 · 1 comment · Fixed by #45185
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@HerringtonDarkholme
Copy link
Contributor

HerringtonDarkholme commented Jun 4, 2021

Bug Report

First, congrats to the new compiler switch!
I don't know if this is intentional since strict optional property semantics seems tricky. Related to #44421.

🔎 Search Terms

strict optional properties, assignability

🕗 Version & Regression Information

Nightly, with strictOptionalProperties on

  • I was unable to test this on prior versions because strictOptionalProperties is a new option

⏯ Playground Link

Playground link with relevant code

💻 Code

declare var a: {[x: string]: number | string }
declare var b: {a: number, b: string}
declare var c: {a: number, b?: string}
declare var d: {a: number, b: string | undefined }
declare var e: {a: number, b?: string | undefined }

a = b // ok
a = c // ok 
a = d // error
a = e // expect error

🙁 Actual behavior

TS allow a = e where the property b might be undefined.

🙂 Expected behavior

TS should report error because of consistency?

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jun 9, 2021
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.4.0 (Beta) milestone Jun 9, 2021
@RyanCavanaugh
Copy link
Member

@ahejlsberg I'm inclined to agree but let's discuss today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
5 participants