elastic/kibana

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

Open

#239,468 建立於 2025年10月17日

在 GitHub 查看
 (4 留言) (0 反應) (1 負責人)TypeScript (19,065 star) (8,021 fork)batch import
Feature:Saved ObjectsTeam:Coregood first issue💝community

描述

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

貢獻者指南

[saved objects] Improve type safety in the saved objects repository · elastic/kibana#239468 | Good First Issue