JS Built-ins
WeakRefderefbeginner

WeakRef.deref β€” access property

πŸ“– Usage Example
const ref = new WeakRef({ v: 42 })
const val = ref.deref()
val?.v  // β†’ 42

Always use optional chaining with deref() in case the object was collected.

WeakRef deref property

new WeakRef({val: 42}).deref()!.val === 42.

Challenge: Access a property through deref.

πŸ’‘ Hints (1)
  • β€’ Use type casting if TypeScript complains about the return type of deref.