File: catchClauseWithTypeAnnotation.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 (75 lines) | stat: -rw-r--r-- 5,097 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
tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.ts(17,36): error TS2339: Property 'foo' does not exist on type 'unknown'.
tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.ts(18,37): error TS2339: Property 'foo' does not exist on type 'unknown'.
tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.ts(19,23): error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified.
tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.ts(20,23): error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified.
tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.ts(29,29): error TS2492: Cannot redeclare identifier 'x' in catch clause.
tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.ts(30,29): error TS2403: Subsequent variable declarations must have the same type.  Variable 'x' must be of type 'boolean', but here has type 'string'.
tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.ts(36,22): error TS2339: Property 'x' does not exist on type '{}'.
tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.ts(37,22): error TS2339: Property 'x' does not exist on type '{}'.
tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.ts(38,27): error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified.
tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.ts(39,27): error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified.


==== tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.ts (10 errors) ====
    type any1 = any;
    type unknown1 = unknown;
    
    function fn(x: boolean) {
    
        // no type annotation allowed other than `any` and `unknown`
        try { } catch (x) { } // should be OK
        try { } catch (x: any) { } // should be OK
        try { } catch (x: any1) { } // should be OK
        try { } catch (x: unknown) { } // should be OK
        try { } catch (x: unknown1) { } // should be OK
        try { } catch (x) { x.foo; } // should be OK
        try { } catch (x: any) { x.foo; } // should be OK
        try { } catch (x: any1) { x.foo; } // should be OK
        try { } catch (x: unknown) { console.log(x); } // should be OK
        try { } catch (x: unknown1) { console.log(x); } // should be OK
        try { } catch (x: unknown) { x.foo; } // error in the body
                                       ~~~
!!! error TS2339: Property 'foo' does not exist on type 'unknown'.
        try { } catch (x: unknown1) { x.foo; } // error in the body
                                        ~~~
!!! error TS2339: Property 'foo' does not exist on type 'unknown'.
        try { } catch (x: Error) { } // error in the type
                          ~~~~~
!!! error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified.
        try { } catch (x: object) { } // error in the type
                          ~~~~~~
!!! error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified.
    
        try { console.log(); }
        // @ts-ignore
        catch (e: number) { // e should not be a `number`
            console.log(e.toLowerCase());
        }
    
        // minor bug: shows that the `catch` argument is skipped when checking scope
        try { } catch (x) { let x: string; }
                                ~
!!! error TS2492: Cannot redeclare identifier 'x' in catch clause.
        try { } catch (x) { var x: string; }
                                ~
!!! error TS2403: Subsequent variable declarations must have the same type.  Variable 'x' must be of type 'boolean', but here has type 'string'.
!!! related TS6203 tests/cases/conformance/statements/tryStatements/catchClauseWithTypeAnnotation.ts:4:13: 'x' was also declared here.
        try { } catch (x) { var x: boolean; }
    
        try { } catch ({ x }) { } // should be OK
        try { } catch ({ x }: any) { x.foo; } // should be OK
        try { } catch ({ x }: any1) { x.foo;} // should be OK
        try { } catch ({ x }: unknown) { console.log(x); } // error in the destructure
                         ~
!!! error TS2339: Property 'x' does not exist on type '{}'.
        try { } catch ({ x }: unknown1) { console.log(x); } // error in the destructure
                         ~
!!! error TS2339: Property 'x' does not exist on type '{}'.
        try { } catch ({ x }: object) { } // error in the type
                              ~~~~~~
!!! error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified.
        try { } catch ({ x }: Error) { } // error in the type
                              ~~~~~
!!! error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified.
    }