Closed
Description
TypeScript Version: 3.7.2
Search Terms:
Type narrowing void
Optional Chaining void
Code
type A = { b: string };
// example of how I try to use it:
async (p: Promise<A>) => {
const a = await p.catch(console.error);
a?.b; // error Property 'b' does not exist on type 'void | A'.
};
// simplified examples:
(a: A | void) => {
a?.b; // error Property 'b' does not exist on type 'void | A'.
a ? a.b : undefined // works
};
(a: A | undefined) => {
a?.b; // works
};
(a: A | null) => {
a?.b; // works
};
Expected behavior:
No errors when using optional chaining with a T | void
if T
contains the fields specified. I guess void
could be represented as a value as undefined
considering that a function that returns undefined
returns type void
.
Not sure if this is feasible
Actual behavior:
compilation error
Metadata
Metadata
Assignees
Labels
No labels