elastic/kibana

[saved objects] Improve type safety in the saved objects repository

Open

#239,468 opened on Oct 17, 2025

View on GitHub
 (4 comments) (0 reactions) (1 assignee)TypeScript (8,021 forks)batch import
Feature:Saved ObjectsTeam:Coregood first issue💝community

Repository metrics

Stars
 (19,065 stars)
PR merge metrics
 (Avg merge 2d 3h) (1,000 merged PRs in 30d)

Description

The is an existing pattern of using // @ts-expect-error MultiGetHit._source is optional comments in the saved object repository code that weakens the type safety. We should use a type guard instead

/**
 * Type guard to check if an item is a GetGetResult.
 */
export function isGetGetResult<TDocument = unknown>(
  item: MgetResponseItem<TDocument>
): item is GetGetResult<TDocument> {
  return (item as MgetMultiGetError).error === undefined;
}

Originally posted by @rudolf in https://github.com/elastic/kibana/pull/224411#discussion_r2348988329

Contributor guide