* Add support for Optional Chaining * Add grammar error for invalid tagged template, more tests * Prototype * PR feedback * Add errors for invalid assignments and a trailing '?.' * Add additional signature help test, fix lint warnings * Fix to insert text for completions * Add initial control-flow analysis for optional chains * PR Feedback and more tests * Update to control flow * Remove mangled smart quotes in comments * Fix lint, PR feedback * Updates to control flow * Switch to FlowCondition for CFA of optional chains * Fix ?. insertion for completions on type variables * Accept API baseline change * Clean up types * improve control-flow debug output * Revert Debug.formatControlFlowGraph helper
76 lines
2.4 KiB
Text
76 lines
2.4 KiB
Text
=== tests/cases/conformance/expressions/optionalChaining/callChain/callChain.3.ts ===
|
|
declare function absorb<T>(): T;
|
|
>absorb : <T>() => T
|
|
|
|
declare const a: { m?<T>(obj: {x: T}): T } | undefined;
|
|
>a : { m?<T>(obj: { x: T; }): T; } | undefined
|
|
>m : (<T>(obj: { x: T; }) => T) | undefined
|
|
>obj : { x: T; }
|
|
>x : T
|
|
|
|
const n1: number = a?.m?.({x: 12 }); // should be an error (`undefined` is not assignable to `number`)
|
|
>n1 : number
|
|
>a?.m?.({x: 12 }) : number | undefined
|
|
>a?.m : (<T>(obj: { x: T; }) => T) | undefined
|
|
>a : { m?<T>(obj: { x: T; }): T; } | undefined
|
|
>m : (<T>(obj: { x: T; }) => T) | undefined
|
|
>{x: 12 } : { x: number; }
|
|
>x : number
|
|
>12 : 12
|
|
|
|
const n2: number = a?.m?.({x: absorb()}); // likewise
|
|
>n2 : number
|
|
>a?.m?.({x: absorb()}) : number | undefined
|
|
>a?.m : (<T>(obj: { x: T; }) => T) | undefined
|
|
>a : { m?<T>(obj: { x: T; }): T; } | undefined
|
|
>m : (<T>(obj: { x: T; }) => T) | undefined
|
|
>{x: absorb()} : { x: number; }
|
|
>x : number
|
|
>absorb() : number
|
|
>absorb : <T>() => T
|
|
|
|
const n3: number | undefined = a?.m?.({x: 12}); // should be ok
|
|
>n3 : number | undefined
|
|
>a?.m?.({x: 12}) : number | undefined
|
|
>a?.m : (<T>(obj: { x: T; }) => T) | undefined
|
|
>a : { m?<T>(obj: { x: T; }): T; } | undefined
|
|
>m : (<T>(obj: { x: T; }) => T) | undefined
|
|
>{x: 12} : { x: number; }
|
|
>x : number
|
|
>12 : 12
|
|
|
|
const n4: number | undefined = a?.m?.({x: absorb()}); // likewise
|
|
>n4 : number | undefined
|
|
>a?.m?.({x: absorb()}) : number | undefined
|
|
>a?.m : (<T>(obj: { x: T; }) => T) | undefined
|
|
>a : { m?<T>(obj: { x: T; }): T; } | undefined
|
|
>m : (<T>(obj: { x: T; }) => T) | undefined
|
|
>{x: absorb()} : { x: number | undefined; }
|
|
>x : number | undefined
|
|
>absorb() : number | undefined
|
|
>absorb : <T>() => T
|
|
|
|
// Also a test showing `!` vs `?` for good measure
|
|
let t1 = a?.m?.({x: 12});
|
|
>t1 : number | undefined
|
|
>a?.m?.({x: 12}) : number | undefined
|
|
>a?.m : (<T>(obj: { x: T; }) => T) | undefined
|
|
>a : { m?<T>(obj: { x: T; }): T; } | undefined
|
|
>m : (<T>(obj: { x: T; }) => T) | undefined
|
|
>{x: 12} : { x: number; }
|
|
>x : number
|
|
>12 : 12
|
|
|
|
t1 = a!.m!({x: 12});
|
|
>t1 = a!.m!({x: 12}) : number
|
|
>t1 : number | undefined
|
|
>a!.m!({x: 12}) : number
|
|
>a!.m! : <T>(obj: { x: T; }) => T
|
|
>a!.m : (<T>(obj: { x: T; }) => T) | undefined
|
|
>a! : { m?<T>(obj: { x: T; }): T; }
|
|
>a : { m?<T>(obj: { x: T; }): T; } | undefined
|
|
>m : (<T>(obj: { x: T; }) => T) | undefined
|
|
>{x: 12} : { x: number; }
|
|
>x : number
|
|
>12 : 12
|
|
|