Improve SavedObjectAttributes type #47334
Labels
Feature:New Platform
Team:Core
Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc
SavedObjectClient methods are currently typed with a generic that must extend
SavedObjectAttributes
:SavedObjectAttributes type
Because of this consumers of the API are forced to provide a generic parameter that extends
SavedObjectAttributes
or theany
type. Extending from theSavedObjectAttributes
type relaxes types to unknown/unspecified keys because of the index signature:Although the
SavedObjectAttributes
type is useful for guaranteeing that a saved object is serializable, the risk of subtle business logic bugs introduced by the weaker type safety is arguable higher than that a SavedObject cannot be serialized.To improve the typings we should:
Don't force SavedObjectsClient method generics to extend from
SavedObjectAttributes
but rather change the method signatures to match:If we're concerned about serializability we could implement something like the following for methods which accept arguments:
Unfortunately it doesn't create very descriptive type errors:
The text was updated successfully, but these errors were encountered: