Skip to content

Instantly share code, notes, and snippets.

@wmakeev
Last active September 6, 2023 11:38
Show Gist options
  • Save wmakeev/7355eb4c6660dfe5fd458189d98690c5 to your computer and use it in GitHub Desktop.
Save wmakeev/7355eb4c6660dfe5fd458189d98690c5 to your computer and use it in GitHub Desktop.
[МойСклад - часто используемые функции] #moysklad #tools #usefull #helpers
/** @type {<T extends import("moysklad-api-model").Attribute["type"]>(entity: { attributes?: import("moysklad-api-model").Attribute[] }, type: T, id: string) => Extract<import("moysklad-api-model").Attribute, { type: T }> | null} */
export const getAttr = (entity, attrType, id) => {
const attr = entity.attributes?.find(
(a) => a.type === attrType && (a.id === id || a.meta.href.endsWith(id))
);
// @ts-expect-error mute
return attr ?? null;
};
type GetMoyskladAttr = <
T extends import("moysklad-api-model").Attribute["type"]
>(
entity: { attributes?: import("moysklad-api-model").Attribute[] },
type: T,
id: string
) => Extract<import("moysklad-api-model").Attribute, { type: T }> | null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment