Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow specyfing string subtype for product ids #1089

Merged
Merged
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
12 changes: 7 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ export interface Discount {
subscriptionPeriod: string;
}

export interface Product extends Common {
export interface Product<ProductId extends string = string> extends Common {
type: 'inapp' | 'iap';
productId: string;
productId: ProductId;
}

export interface Subscription extends Common {
Expand Down Expand Up @@ -218,14 +218,16 @@ export const consumeAllItemsAndroid = (): Promise<string[]> =>
* @param {string[]} skus The item skus
* @returns {Promise<Product[]>}
*/
export const getProducts = (skus: string[]): Promise<Product[]> =>
export const getProducts = <SkuType extends string>(
skus: SkuType[],
): Promise<Array<Product<SkuType>>> =>
Platform.select({
ios: async () => {
if (!RNIapIos) {
return [];
}
return RNIapIos.getItems(skus).then((items: Product[]) =>
items.filter((item: Product) => item.productId),
return RNIapIos.getItems(skus).then((items: Product<SkuType>[]) =>
items.filter((item: Product<SkuType>) => item.productId),
);
},
android: async () => {
Expand Down