File: typeParameterConstModifiers.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 (92 lines) | stat: -rw-r--r-- 3,296 bytes parent folder | download
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterConstModifiers.ts(45,14): error TS1277: 'const' modifier can only appear on a type parameter of a function, method or class
tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterConstModifiers.ts(51,9): error TS1277: 'const' modifier can only appear on a type parameter of a function, method or class


==== tests/cases/conformance/types/typeParameters/typeParameterLists/typeParameterConstModifiers.ts (2 errors) ====
    declare function f1<const T>(x: T): T;
    
    const x11 = f1('a');
    const x12 = f1(['a', ['b', 'c']]);
    const x13 = f1({ a: 1, b: "c", d: ["e", 2, true, { f: "g" }] });
    
    declare function f2<const T, U>(x: T | undefined): T;
    
    const x21 = f2('a');
    const x22 = f2(['a', ['b', 'c']]);
    const x23 = f2({ a: 1, b: "c", d: ["e", 2, true, { f: "g" }] });
    
    declare function f3<const T>(x: T): T[];
    
    const x31 = f3("hello");
    const x32 = f3("hello");
    
    declare function f4<const T>(obj: [T, T]): T;
    
    const x41 = f4([[1, 'x'], [2, 'y']]);
    const x42 = f4([{ a: 1, b: 'x' }, { a: 2, b: 'y' }]);
    
    declare function f5<const T>(obj: { x: T, y: T }): T;
    
    const x51 = f5({ x: [1, 'x'], y: [2, 'y'] });
    const x52 = f5({ x: { a: 1, b: 'x' }, y: { a: 2, b: 'y' } });
    
    declare function f6<const T extends readonly unknown[]>(...args: T): T;
    
    const x61 = f6(1, 'b', { a: 1, b: 'x' });
    
    class C1<const T> {
        constructor(x: T) {}
        foo<const U>(x: U) { return x; }
    }
    
    const c71 = new C1({ a: 1, b: "c", d: ["e", 2, true, { f: "g" }] });
    const c72 = c71.foo(['a', ['b', 'c']]);
    
    const C2 = class <const T> {}
    
    const fx1 = <const T>(x: T) => x;
    const fx2 = <const T,>(x: T) => x;
    
    interface I1<const T> { x: T }  // Error
                 ~~~~~
!!! error TS1277: 'const' modifier can only appear on a type parameter of a function, method or class
    
    interface I2 {
        f<const T>(x: T): T;
    }
    
    type T1<const T> = T;  // Error
            ~~~~~
!!! error TS1277: 'const' modifier can only appear on a type parameter of a function, method or class
    
    type T2 = <const T>(x: T) => T;
    type T3 = { <const T>(x: T): T };
    type T4 = new <const T>(x: T) => T;
    type T5 = { new <const T>(x: T): T };
    
    // Corrected repro from #51745
    
    type Obj = { a: { b: { c: "123" } } };
    
    type GetPath<T, P> =
        P extends readonly [] ? T :
        P extends readonly [infer A extends keyof T, ...infer Rest] ? GetPath<T[A], Rest> :
        never;
    
    function set<T, const P extends readonly string[]>(obj: T, path: P, value: GetPath<T, P>) {}
    
    declare let obj: Obj;
    declare let value: "123";
    
    set(obj, ['a', 'b', 'c'], value);
    
    // Repro from #52007
    
    declare function inners<const T extends readonly any[]>(...args: readonly [unknown, ...T, unknown]): T;
    
    const test = inners(1,2,3,4,5);
    
    declare function inners2<const T extends readonly any[]>(args: readonly [unknown, ...T, unknown]): T;
    
    const test2 = inners2([1,2,3,4,5]);