Skip to content

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

@TinaHeiligers

Description

@TinaHeiligers

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 #224411 (comment)

Metadata

Metadata

Assignees

Labels

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions