Closed
Description
TypeScript Version: 3.7.2
Search Terms:
optional chaining
Code
interface Maybe<A> { };
export declare function Maybe<A>(value: A | null | undefined): Maybe<A>;
declare const ctx: {req?: {headers?: {cookie?: string}}}
const testopt = ctx.req?.headers?.cookie
const teststring = "" as string | undefined;
const test = Maybe(testopt) // Maybe<string | undefined> (wrong)
const test1 = Maybe(teststring ) // Maybe<string> (correct)
Expected behavior:
const test
should be of type Maybe<string>
like const test1
because this is the behavior of inference on a function with this signature.
Actual behavior:
const test
is of type Maybe<string | undefined
;