diff --git a/types/instafeed.js/index.d.ts b/types/instafeed.js/index.d.ts index 75ade7686f3801..a8a7cc88b0fd8b 100644 --- a/types/instafeed.js/index.d.ts +++ b/types/instafeed.js/index.d.ts @@ -19,8 +19,8 @@ declare namespace Instafeed { apiLimit?: number; before?: () => void; debug?: boolean; - error?: (err: unknown) => any; - filter?: (item: InstagramDataItem) => boolean; + error?: (err: Error) => any; + filter?: (item: T) => boolean; limit?: number; mock?: boolean; render?: (item: T, options: Instafeed.InstafeedOptions) => string; @@ -29,30 +29,39 @@ declare namespace Instafeed { target?: string | Element; template?: string; templateBoundaries?: string[]; - transform?: (item: InstagramDataItem) => Record; + transform?: (item: InstafeedDefaultItem) => T; } interface InstafeedDefaultItem { caption: string; - tags: string[]; id: string; image: string; link: string; model: InstagramDataItem; + tags: string[]; timestamp: string; type: string; username: string; } - interface InstagramDataItem { + type InstagramDataItem = { caption: string; id: string; - media_type: string; + media_type: "CAROUSEL_ALBUM" | "IMAGE"; media_url: string; permalink: string; timestamp: string; username: string; - } + } | { + caption: string; + id: string; + media_type: "VIDEO"; + media_url: string; + permalink: string; + thumbnail_url: string; + timestamp: string; + username: string; + }; interface InstagramPaging { cursors: { diff --git a/types/instafeed.js/instafeed.js-tests.ts b/types/instafeed.js/instafeed.js-tests.ts index 47244727e46143..49501a75c85d77 100644 --- a/types/instafeed.js/instafeed.js-tests.ts +++ b/types/instafeed.js/instafeed.js-tests.ts @@ -1,4 +1,5 @@ import Instafeed = require("instafeed.js"); +import { type InstafeedDefaultItem } from "instafeed.js"; // $ExpectType Instafeed new Instafeed({ accessToken: "aa" }); @@ -11,3 +12,29 @@ new Instafeed({}); // @ts-expect-error new Instafeed(); + +// test if transform return type is passed to other hooks +new Instafeed({ + accessToken: "aa", + transform(item) { + return { ...item, extra: "foo" }; + }, + filter(item) { + // $ExpectType string + item.extra; + return true; + }, +}); + +interface CustomInstafeedItem extends InstafeedDefaultItem { + extra: string; +} + +// test if omiting expected extra field breaks compiler as expected +new Instafeed({ + accessToken: "aa", + // @ts-expect-error + transform(item) { + return item; + }, +});