File: genericUnboundedTypeParamAssignability.errors.txt

package info (click to toggle)
node-typescript 5.0.4%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 459,116 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (36 lines) | stat: -rw-r--r-- 1,896 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
tests/cases/compiler/genericUnboundedTypeParamAssignability.ts(2,5): error TS2339: Property 'toString' does not exist on type 'T'.
tests/cases/compiler/genericUnboundedTypeParamAssignability.ts(15,6): error TS2345: Argument of type 'T' is not assignable to parameter of type '{}'.
tests/cases/compiler/genericUnboundedTypeParamAssignability.ts(16,6): error TS2345: Argument of type 'T' is not assignable to parameter of type 'Record<string, any>'.
tests/cases/compiler/genericUnboundedTypeParamAssignability.ts(17,5): error TS2339: Property 'toString' does not exist on type 'T'.


==== tests/cases/compiler/genericUnboundedTypeParamAssignability.ts (4 errors) ====
    function f1<T>(o: T) {
      o.toString(); // error
        ~~~~~~~~
!!! error TS2339: Property 'toString' does not exist on type 'T'.
    }
    
    function f2<T extends {}>(o: T) {
      o.toString(); // no error
    }
    
    function f3<T extends Record<string, any>>(o: T) {
      o.toString(); // no error
    }
    
    function user<T>(t: T) {
      f1(t);
      f2(t); // error in strict, unbounded T doesn't satisfy the constraint
         ~
!!! error TS2345: Argument of type 'T' is not assignable to parameter of type '{}'.
!!! related TS2208 tests/cases/compiler/genericUnboundedTypeParamAssignability.ts:13:15: This type parameter might need an `extends {}` constraint.
      f3(t); // error in strict, unbounded T doesn't satisfy the constraint
         ~
!!! error TS2345: Argument of type 'T' is not assignable to parameter of type 'Record<string, any>'.
!!! related TS2208 tests/cases/compiler/genericUnboundedTypeParamAssignability.ts:13:15: This type parameter might need an `extends Record<string, any>` constraint.
      t.toString();  // error, for the same reason as f1()
        ~~~~~~~~
!!! error TS2339: Property 'toString' does not exist on type 'T'.
    }