add helpers for private-named instance fields#77
add helpers for private-named instance fields#77DanielRosenwasser merged 1 commit intomicrosoft:masterfrom
Conversation
| export declare function __importStar<T>(mod: T): T; | ||
| export declare function __importDefault<T>(mod: T): T | { default: T }; | ||
| export declare function __classPrivateFieldGet(receiver: any, privateMap: WeakMap<any, any>): any; | ||
| export declare function __classPrivateFieldSet(receiver: any, privateMap: WeakMap<any, any>, value: any): any; |
There was a problem hiding this comment.
Should these function declarations be genericized? My instinct is that they should, but I'm not sure which generic form would be appropriate, given the lack of generics in other function declarations in this file.
Each of these methods returns a value of a known type. That would make me want to write the following.
export declare function __classPrivateFieldGet<T>(receiver: any, privateMap: WeakMap<any, T>): T;
export declare function __classPrivateFieldSet<T>(receiver: any, privateMap: WeakMap<any, T>, value: T): T;However, I don't understand why WeakMap<any, ...> is allowed, given that JS WeakMap.get/set only accept an object as the first parameter. The following TypeScript compiles fine but fails at runtime.
// typescript
const m: WeakMap<any, any> = new WeakMap<any, any>();
m.set(false, true);// emitted javascript
const m = new WeakMap();
m.set(false, true); // fails at runtimeI would have expected TS's definition to be WeakMap<K extends object, T>. If that were the case, I believe the generic form would be something like the following
export declare function __classPrivateFieldGet<K extends object, T>(receiver: K, privateMap: WeakMap<K, T>): T;
export declare function __classPrivateFieldSet<K extends object, T>(receiver: K, privateMap: WeakMap<K, T>, value: T): T;There was a problem hiding this comment.
Yes, they should be generic, so I’m doing that in #82.
|
Requesting a review from @rbuckton. |
|
for reviewers: this PR is still up-to-date with microsoft/TypeScript#30829 |
A companion to microsoft/TypeScript#30829, this PR adds the helper methods for private-named instance fields into tslib.
The original helper methods were written by @joeywatts and @mheiber in the aforementioned PR. They have simply been copied and exposed here.