isDocument

See source code

Type guard to check if a record is a TLDocument. Useful for filtering or type narrowing when working with mixed record types.

function isDocument(record?: UnknownRecord): record is TLDocument

Example

// Type guard usage
function processRecord(record: UnknownRecord) {
  if (isDocument(record)) {
    // record is now typed as TLDocument
    console.log(`Document: ${record.name}, Grid: ${record.gridSize}px`)
  }
}

// Filter documents from mixed records
const allRecords = store.allRecords()
const documents = allRecords.filter(isDocument) // Should be exactly one

Parameters

NameDescription

record

The record to check

Returns

record is TLDocument

True if the record is a document, false otherwise

Prev
isBindingId
Next
isPageId