#Error from `exactOptionalPropertyTypes` incorrectly silenced by ternary

7 messages · Page 1 of 1 (latest)

lusty seal
#

I've used this pattern before and never seen this issue, isn't this a bug?

solar cedarBOT
#
mishall8399#0

Preview:```ts
import {Types} from "mongoose"

type ReceivedCtx = {
requestBody: {
parentId?: Types.ObjectId
}
}

type ExpectedParameters = {
parent?: Types.ObjectId
}

function update(args: ExpectedParameters) {
// something
}

declare const ctx: ReceivedCtx
...```

trim ridge
#

Here's a more minimal reproduction:

solar cedarBOT
#
nonspicyburrito#0

Preview:```ts
type Foo = {x?: number}

declare const a: number | undefined
declare const source: Foo
const b = source.x

let target: Foo
target = true ? {x: a} : {}
target = true ? {x: b} : {}
target = true ? {x: source.x} : {}
target = {...{x: a}}
target = {...{x: b}}
...```

trim ridge
#

Seems like a very specific bug, it requires all 3 of spread + ternary + accessing an optional value from object, and doesn't happen if any of that is missing as seen in the repro.

lusty seal
#

Huh weird. I guess that also explains why I haven't seen it before, I probably didn't have a object property access
I'll raise an issue on Github, thank you!!

#

!resolved