Closed
Description
π Search Terms
exactOptionalPropertyTypes
π Version & Regression Information
- This changed between versions
typescript@5.2
andtypescript@5.3.0-dev.20230816
(still happening intypescript@5.3.0-dev.20230825
)
β― Playground Link
π» Code
export function main(a: string[] | undefined) {
const z = a //
? { a }
: { b: ["there"] };
z.a //
? z.a.toString()
: z.b.toString(); // ts@5.3 error on `z.b` here when `exactOptionalPropertyTypes` is enabled
// work-around #1
const zWorkAround: { a: string[], b?: undefined } | { b: string[], a?: undefined } = z;
zWorkAround.a //
? zWorkAround.a.toString()
: zWorkAround.b.toString();
// work-around #2
"a" in z // this is **ONLY** a valid workaround when `exactOptionalPropertyTypes` **IS** enabled
? z.a.toString()
: z.b.toString();
}
π Actual behavior
Errors in code
'z.b' is possibly 'undefined'.
π Expected behavior
Try any pervious version (I checked back to typescript@4.0
) and the CFA from the !!z.a
branch works fine.
Additional information about the issue
An interesting little problem/tidbit back to typescript@4.4
is this IntelliSense:
Why is a
optional in the "a" in zWorkaround2
branch?
Activity
Andarist commentedon Aug 29, 2023
It might be the regression from #54777 that im investigating
[-][next/nightly] Incorrect _'obj.prop' is possibly 'undefined'._ Error in CFA with `exactOptionalPropertyTypes` and Optional-Never Properties[/-][+][next/nightly] Incorrect _'obj.prop' is possibly 'undefined'._ Error in CFA with `exactOptionalPropertyTypes` and Optional-`never` Properties[/+]