File: callChain.3.errors.txt

package info (click to toggle)
node-typescript 4.9.5%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 533,908 kB
  • sloc: javascript: 2,018,330; makefile: 7; sh: 1
file content (23 lines) | stat: -rw-r--r-- 1,399 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
tests/cases/conformance/expressions/optionalChaining/callChain/callChain.3.ts(3,7): error TS2322: Type 'number | undefined' is not assignable to type 'number'.
  Type 'undefined' is not assignable to type 'number'.
tests/cases/conformance/expressions/optionalChaining/callChain/callChain.3.ts(4,7): error TS2322: Type 'number | undefined' is not assignable to type 'number'.
  Type 'undefined' is not assignable to type 'number'.


==== tests/cases/conformance/expressions/optionalChaining/callChain/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});