File: mismatchedExplicitTypeParameterAndArgumentType.errors.txt

package info (click to toggle)
node-typescript 5.0.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 459,140 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (21 lines) | stat: -rw-r--r-- 1,092 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(10,34): error TS2322: Type 'string' is not assignable to type 'number'.
tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,15): error TS2558: Expected 2 type arguments, but got 1.


==== tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts (2 errors) ====
    function map<T, U>(xs: T[], f: (x: T) => U) {
        var ys: U[] = [];
        xs.forEach(x => ys.push(f(x)));
        return ys;
    }
    
    var r0 = map([1, ""], (x) => x.toString());
    var r5 = map<any, any>([1, ""], (x) => x.toString());
    var r6 = map<Object, Object>([1, ""], (x) => x.toString());
    var r7 = map<number, string>([1, ""], (x) => x.toString()); // error
                                     ~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
    var r7b = map<number>([1, ""], (x) => x.toString()); // error
                  ~~~~~~
!!! error TS2558: Expected 2 type arguments, but got 1.
    var r8 = map<any, string>([1, ""], (x) => x.toString());