File: localTypes4.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 (53 lines) | stat: -rw-r--r-- 1,691 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
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
tests/cases/conformance/types/localTypes/localTypes4.ts(10,19): error TS2304: Cannot find name 'T'.
tests/cases/conformance/types/localTypes/localTypes4.ts(10,23): error TS2304: Cannot find name 'T'.
tests/cases/conformance/types/localTypes/localTypes4.ts(18,16): error TS2300: Duplicate identifier 'T'.
tests/cases/conformance/types/localTypes/localTypes4.ts(19,19): error TS2300: Duplicate identifier 'T'.


==== tests/cases/conformance/types/localTypes/localTypes4.ts (4 errors) ====
    function f1() {
        // Type parameters are in scope in parameters and return types
        function f<T>(x: T): T {
            return undefined;
        }
    }
    
    function f2() {
        // Local types are not in scope in parameters and return types
        function f(x: T): T {
                      ~
!!! error TS2304: Cannot find name 'T'.
                          ~
!!! error TS2304: Cannot find name 'T'.
            interface T { }
            return undefined;
        }
    }
    
    function f3() {
        // Type parameters and top-level local types are in same declaration space
        function f<T>() {
                   ~
!!! error TS2300: Duplicate identifier 'T'.
            interface T { }
                      ~
!!! error TS2300: Duplicate identifier 'T'.
            return undefined;
        }
    }
    
    function f4() {
        // Local types are block scoped
        interface T { x: number }
        let v: T;
        v.x = 10;
        if (true) {
            interface T { x: string }
            let v: T;
            v.x = "hello";
        }
        else {
            v.x = 20;
        }
    }