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
|
tests/cases/conformance/classes/members/privateNames/privateNamesInGenericClasses.ts(22,3): error TS18013: Property '#foo' is not accessible outside class 'C' because it has a private identifier.
tests/cases/conformance/classes/members/privateNames/privateNamesInGenericClasses.ts(23,3): error TS18013: Property '#method' is not accessible outside class 'C' because it has a private identifier.
tests/cases/conformance/classes/members/privateNames/privateNamesInGenericClasses.ts(24,3): error TS18013: Property '#prop' is not accessible outside class 'C' because it has a private identifier.
tests/cases/conformance/classes/members/privateNames/privateNamesInGenericClasses.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/privateNamesInGenericClasses.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/privateNamesInGenericClasses.ts (5 errors) ====
class C<T> {
#foo: T;
#method(): T { return this.#foo; }
get #prop(): T { return this.#foo; }
set #prop(value : T) { this.#foo = value; }
bar(x: C<T>) { return x.#foo; } // OK
bar2(x: C<T>) { return x.#method(); } // OK
bar3(x: C<T>) { return x.#prop; } // OK
baz(x: C<number>) { return x.#foo; } // OK
baz2(x: C<number>) { return x.#method; } // OK
baz3(x: C<number>) { return x.#prop; } // OK
quux(x: C<string>) { return x.#foo; } // OK
quux2(x: C<string>) { return x.#method; }// OK
quux3(x: C<string>) { return x.#prop; } // OK
}
declare let a: C<number>;
declare let b: C<string>;
a.#foo; // Error
~~~~
!!! error TS18013: Property '#foo' is not accessible outside class 'C' because it has a private identifier.
a.#method; // Error
~~~~~~~
!!! error TS18013: Property '#method' is not accessible outside class 'C' because it has a private identifier.
a.#prop; // Error
~~~~~
!!! error TS18013: Property '#prop' 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'.
|