Skip to content

Instantly share code, notes, and snippets.

@jonsmithers
Last active November 11, 2020 19:49
Show Gist options
  • Save jonsmithers/2dd45399fafdc03f1e2cab8e8039e815 to your computer and use it in GitHub Desktop.
Save jonsmithers/2dd45399fafdc03f1e2cab8e8039e815 to your computer and use it in GitHub Desktop.
WeakRef type definition
/**
* WeakRef is supported by major browsers but doesn't appear to be available in
* Typescript 4.0.5. Here is a temporary type definition until TypeScript adds
* native support.
*
* See https://github.com/microsoft/TypeScript/issues/32393
*/
interface WeakRef<V> {
deref(): V | undefined;
}
interface WeakRefConstructor {
new <V = any>(v: V): WeakRef<V>;
readonly prototype: WeakRef<any>;
}
/* eslint-disable-next-line @typescript-eslint/no-redeclare */
declare var WeakRef: WeakRefConstructor;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment