Last active
September 6, 2023 11:38
-
-
Save wmakeev/7355eb4c6660dfe5fd458189d98690c5 to your computer and use it in GitHub Desktop.
[МойСклад - часто используемые функции] #moysklad #tools #usefull #helpers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @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; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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