Closed
Description
π Search Terms
exactOptionalPropertyTypes
π Version & Regression Information
- This changed between versions
[email protected]
and[email protected]
(still happening in[email protected]
)
β― Playground Link
π» Code
export function main(a: string[] | undefined) {
const z = a //
? { a }
: { b: ["there"] };
z.a //
? z.a.toString()
: z.b.toString(); // [email protected] 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 [email protected]
) and the CFA from the !!z.a
branch works fine.
Additional information about the issue
An interesting little problem/tidbit back to [email protected]
is this IntelliSense:
Why is a
optional in the "a" in zWorkaround2
branch?