Skip to content

Commit c4e0be1

Browse files
committed
Add WeakRef type
1 parent a13fdb1 commit c4e0be1

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

types/WeakRef.d.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// <reference no-default-lib="true"/>
2+
/// <reference types="@rbxts/types"/>
3+
4+
/**
5+
* A WeakRef object is a reference to an object that does not prevent the object from being garbage collected.
6+
* Note that references to Roblox instances are never weak.
7+
*/
8+
interface WeakRef<T extends object> {
9+
/**
10+
* **DO NOT USE!**
11+
*
12+
* This field exists to force TypeScript to recognize this as a nominal type
13+
* @hidden
14+
* @deprecated
15+
*/
16+
readonly _nominal_WeakRef: unique symbol;
17+
18+
/**
19+
* Returns the WeakRef instance's target value, or undefined if the target value has been reclaimed.
20+
*/
21+
deref(): T | undefined;
22+
}
23+
24+
interface WeakRefConstructor {
25+
/**
26+
* Creates a WeakRef instance for the given target value.
27+
* @param target The target value for the WeakRef instance.
28+
*/
29+
new <T extends object>(target: T): WeakRef<T>;
30+
}
31+
declare const WeakRef: WeakRefConstructor;

0 commit comments

Comments
 (0)