mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
27 lines
505 B
TypeScript
27 lines
505 B
TypeScript
import weak = require('weak-napi');
|
|
|
|
const obj = {a: 123};
|
|
|
|
const weakReference = weak(obj, () => {
|
|
// collected
|
|
});
|
|
|
|
const sameType = weak.get(weakReference);
|
|
|
|
function foo(a: {a: number}) {}
|
|
|
|
if (sameType) {
|
|
foo(sameType);
|
|
}
|
|
|
|
const anyVar = null as any;
|
|
|
|
if (weak.isWeakRef(anyVar)) {
|
|
const a = anyVar; // WeakRef<any>
|
|
}
|
|
|
|
if (weak.isDead(weakReference)) {
|
|
const a = weakReference; // $ExpectType WeakRef<undefined>
|
|
const value = weak.get(weakReference); // undefined only possible
|
|
}
|