forked from microsoft/TypeScript
/
privateNameAndAny.js
53 lines (51 loc) · 1.24 KB
/
privateNameAndAny.js
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
//// [privateNameAndAny.ts]
class A {
#foo = true;
method(thing: any) {
thing.#foo; // OK
thing.#bar; // Error
thing.#foo();
}
methodU(thing: unknown) {
thing.#foo;
thing.#bar;
thing.#foo();
}
methodN(thing: never) {
thing.#foo;
thing.#bar;
thing.#foo();
}
};
//// [privateNameAndAny.js]
"use strict";
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to get private field on non-instance");
}
return privateMap.get(receiver);
};
var _foo;
class A {
constructor() {
_foo.set(this, true);
}
method(thing) {
__classPrivateFieldGet(thing, _foo); // OK
thing.; // Error
__classPrivateFieldGet(thing, _foo).call(// Error
thing);
}
methodU(thing) {
__classPrivateFieldGet(thing, _foo);
thing.;
__classPrivateFieldGet(thing, _foo).call(thing);
}
methodN(thing) {
__classPrivateFieldGet(thing, _foo);
thing.;
__classPrivateFieldGet(thing, _foo).call(thing);
}
}
_foo = new WeakMap();
;