File: privateNamesAndGenericClasses-2.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 (43 lines) | stat: -rw-r--r-- 1,851 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
37
38
39
40
41
42
43
tests/cases/conformance/classes/members/privateNames/privateNamesAndGenericClasses-2.ts(24,3): error TS18013: Property '#foo' is not accessible outside class 'C' because it has a private identifier.
tests/cases/conformance/classes/members/privateNames/privateNamesAndGenericClasses-2.ts(25,1): error TS2322: Type 'C<string>' is not assignable to type 'C<number>'.
  Type 'string' is not assignable to type 'number'.
tests/cases/conformance/classes/members/privateNames/privateNamesAndGenericClasses-2.ts(26,1): error TS2322: Type 'C<number>' is not assignable to type 'C<string>'.
  Type 'number' is not assignable to type 'string'.


==== tests/cases/conformance/classes/members/privateNames/privateNamesAndGenericClasses-2.ts (3 errors) ====
    class C<T> {
        #foo: T;
        #bar(): T {
          return this.#foo;
        }
        constructor(t: T) {
          this.#foo = t;
          t = this.#bar();
        }
        set baz(t: T) {
          this.#foo = t;
    
        }
        get baz(): T {
          return this.#foo;
        }
    }
    
    let a = new C(3);
    let b = new C("hello");
    
    a.baz = 5                                 // OK
    const x: number = a.baz                   // OK
    a.#foo;                                   // Error
      ~~~~
!!! error TS18013: Property '#foo' is not accessible outside class 'C' because it has a private identifier.
    a = b;                                    // Error
    ~
!!! error TS2322: Type 'C<string>' is not assignable to type 'C<number>'.
!!! error TS2322:   Type 'string' is not assignable to type 'number'.
    b = a;                                    // Error
    ~
!!! error TS2322: Type 'C<number>' is not assignable to type 'C<string>'.
!!! error TS2322:   Type 'number' is not assignable to type 'string'.