⭐️ If you like MikroORM, give it a star on GitHub and consider sponsoring its development! ⭐️
This is documentation for an unreleased version. For the latest API, see version 7.0.
Version: Next
unref
Callable
unref<V>(value): V | undefined
unref<T>(value): T
unref<T>(value): T | null
unref<T>(value): T | undefined
unref<T>(value): T | null | undefined
Unwraps a reference to its underlying value, returning the entity or scalar. Works on any of:
Ref<T> / Reference<T> (entity) — calls .unwrap() to extract the wrapped entity, returns T.
LazyRef<T> — type-only marker; runtime value is already T, so returned as-is.
plain entity T — returned as-is.
ScalarReference<V> / ScalarRef<V> — calls .unwrap() to extract the scalar value, returns V | undefined
(a scalar reference may be bound without an initial value).
Inverse of the ref helper. Use as a typed escape hatch when you know a relation is populated
but don't want to (or can't) thread Loaded<T, 'relation'> through a function signature.
functionlogAuthor(book: Book){
// `book.author` is typed as `LazyRef<Author>`, so `.name` is not directly accessible
Note: unref is a compile-time narrowing only for entity refs. On a LazyRef<T> or plain entity
relation that is a stub (PK only, never populated), reads of non-PK properties will still return
undefined at runtime — same footgun as a plain non-Ref relation.
Unwraps a reference to its underlying value, returning the entity or scalar. Works on any of:
Ref<T>/Reference<T>(entity) — calls.unwrap()to extract the wrapped entity, returnsT.LazyRef<T>— type-only marker; runtime value is alreadyT, so returned as-is.T— returned as-is.ScalarReference<V>/ScalarRef<V>— calls.unwrap()to extract the scalar value, returnsV | undefined(a scalar reference may be bound without an initial value).Inverse of the ref helper. Use as a typed escape hatch when you know a relation is populated but don't want to (or can't) thread
Loaded<T, 'relation'>through a function signature.Note:
unrefis a compile-time narrowing only for entity refs. On aLazyRef<T>or plain entity relation that is a stub (PK only, never populated), reads of non-PK properties will still returnundefinedat runtime — same footgun as a plain non-Refrelation.