Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions types/instafeed.js/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,30 +29,39 @@ declare namespace Instafeed {
target?: string | Element;
template?: string;
templateBoundaries?: string[];
transform?: (item: InstagramDataItem) => Record<string, unknown>;
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: {
Expand Down
27 changes: 27 additions & 0 deletions types/instafeed.js/instafeed.js-tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Instafeed = require("instafeed.js");
import { type InstafeedDefaultItem } from "instafeed.js";

// $ExpectType Instafeed<InstafeedDefaultItem>
new Instafeed({ accessToken: "aa" });
Expand All @@ -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<CustomInstafeedItem>({
accessToken: "aa",
// @ts-expect-error
transform(item) {
return item;
},
});