跳到主要内容

tryGetEntityMetadata()

function tryGetEntityMetadata(target):
| Readonly<EntityMetadataType>
| undefined;

Defined in: packages/rxdb/src/rxdb-utils.ts:59

探测实体元数据:查不到返回 undefined,不抛错。

Parameters​

ParameterTypeDescription
targetunknown任意对象;不要求它是实体

Returns​

| Readonly<EntityMetadataType> | undefined

实体元数据对象,没有则 undefined

Remarks​

getEntityMetadata 改成 fail-fast 之后,真正需要探测的调用点必须显式说出来, 而不是靠「反正返回 undefined」蒙混过去。目前唯一的合法探测是 metadata-transition.ts 沿原型链往上找父类元数据 —— 走到没有元数据的那一层就是终止条件, 不是错误。