feat(lib/es2021): Add type parameter to FinalizationRegistry (#42274)

* feat(lib/es2021): Add type parameter to `FinalizationRegistry`

* test(lib/es2021): Add test for generic `FinalizationRegistry`
This commit is contained in:
ExE Boss
2021-02-19 01:43:36 +01:00
committed by GitHub
parent 9950b6e596
commit 0723904bfb
5 changed files with 1042 additions and 5 deletions

View File

@@ -15,12 +15,12 @@ interface WeakRefConstructor {
* Creates a WeakRef instance for the given target object.
* @param target The target object for the WeakRef instance.
*/
new<T extends object>(target?: T): WeakRef<T>;
new<T extends object>(target: T): WeakRef<T>;
}
declare var WeakRef: WeakRefConstructor;
interface FinalizationRegistry {
interface FinalizationRegistry<T> {
readonly [Symbol.toStringTag]: "FinalizationRegistry";
/**
@@ -32,7 +32,7 @@ interface FinalizationRegistry {
* object. If provided (and not undefined), this must be an object. If not provided, the target
* cannot be unregistered.
*/
register(target: object, heldValue: any, unregisterToken?: object): void;
register(target: object, heldValue: T, unregisterToken?: object): void;
/**
* Unregisters an object from the registry.
@@ -43,13 +43,13 @@ interface FinalizationRegistry {
}
interface FinalizationRegistryConstructor {
readonly prototype: FinalizationRegistry;
readonly prototype: FinalizationRegistry<any>;
/**
* Creates a finalization registry with an associated cleanup callback
* @param cleanupCallback The callback to call after an object in the registry has been reclaimed.
*/
new(cleanupCallback: (heldValue: any) => void): FinalizationRegistry;
new<T>(cleanupCallback: (heldValue: T) => void): FinalizationRegistry<T>;
}
declare var FinalizationRegistry: FinalizationRegistryConstructor;