Closed
Description
Bug Report
π Search Terms
- object
- optional properties
- undefined
- conditional assignment
π Version & Regression Information
- This is the behavior in every version I have tried
β― Playground Link
Playground link with relevant code
π» Code
type Foo = { one: boolean | undefined }
type Bar = {one: boolean}
const foo: Foo = {one: undefined};
const barOne: Bar = foo.one !== undefined ? foo : { one: true };
const barTwo: Bar = foo.one !== undefined ? {one: foo.one} : { one: true }
π Actual behavior
The assignment for barOne
throws an error but the assignment for barTwo
does not.
π Expected behavior
I was expecting that either both of them fail or that none of them is failing.
π
Apologies if this is not a Bug but I dont get it and I could not find any explanation for this online.
I got stuck for quite a while with this Issue. My problem is that I dont understand why an conditional assignmnet like the one for barOne
is failing. Then I discovered that when I do the assignment like I did for barTwo
, Typescript isnt complaining.
I would expect that eiter both of them throw an error or both of them dont throw one.