mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
23 lines
1.2 KiB
Plaintext
23 lines
1.2 KiB
Plaintext
callChain.3.ts(3,7): error TS2322: Type 'number | undefined' is not assignable to type 'number'.
|
|
Type 'undefined' is not assignable to type 'number'.
|
|
callChain.3.ts(4,7): error TS2322: Type 'number | undefined' is not assignable to type 'number'.
|
|
Type 'undefined' is not assignable to type 'number'.
|
|
|
|
|
|
==== callChain.3.ts (2 errors) ====
|
|
declare function absorb<T>(): T;
|
|
declare const a: { m?<T>(obj: {x: T}): T } | undefined;
|
|
const n1: number = a?.m?.({x: 12 }); // should be an error (`undefined` is not assignable to `number`)
|
|
~~
|
|
!!! error TS2322: Type 'number | undefined' is not assignable to type 'number'.
|
|
!!! error TS2322: Type 'undefined' is not assignable to type 'number'.
|
|
const n2: number = a?.m?.({x: absorb()}); // likewise
|
|
~~
|
|
!!! error TS2322: Type 'number | undefined' is not assignable to type 'number'.
|
|
!!! error TS2322: Type 'undefined' is not assignable to type 'number'.
|
|
const n3: number | undefined = a?.m?.({x: 12}); // should be ok
|
|
const n4: number | undefined = a?.m?.({x: absorb()}); // likewise
|
|
|
|
// Also a test showing `!` vs `?` for good measure
|
|
let t1 = a?.m?.({x: 12});
|
|
t1 = a!.m!({x: 12}); |