-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add helpers for private-named instance fields #77
add helpers for private-named instance fields #77
Conversation
@@ -32,3 +32,5 @@ export declare function __asyncValues(o: any): any; | |||
export declare function __makeTemplateObject(cooked: string[], raw: string[]): TemplateStringsArray; | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 runtime
I 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.