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

TypeScript Improvements #235

Merged
merged 5 commits into from
Aug 18, 2018
Merged

Conversation

LinusU
Copy link
Member

@LinusU LinusU commented Aug 15, 2018

Recently started using the library in a TypeScript project and noticed a few things that could be improved. Thanks for a great library!

Here are some examples of the improvements seen from VS Code:

screen shot 2018-08-15 at 12 23 43

screen shot 2018-08-15 at 12 30 29

I haven't had time to type up the response for validateReceiptAndroid yet, but hopefully there will be another pull request soonβ„’ πŸš€

This was referenced Aug 15, 2018
}

export const SkuTypes: SkuTypes
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm removing this because it wasn't actually exported from index.js, so trying to use it would just result in undefined at runtime.

I'm planning on fixing this by normalizing the type property so that it's the same on Android and iOS, expect a PR for that soonβ„’ 😎

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's good plan. But breaks compatibility, so I think we'll have to deal with this change separately.

Copy link
Member Author

@LinusU LinusU Aug 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But breaks compatibility

The change in this PR wouldn't though? Because there are no SkuTypes actually exported from index.js?

I still think that we should change it though, shouldn't be a problem to introduce breaking changes since we are in an alpha release?

Copy link
Member

@cometkim cometkim Aug 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry. I confused. Removing SkuTypes variable is good.

But SkuType type

export interface Product {
-  type: SkuTypeAndroid | SkuTypeIOS;
+  type: 'inapp' | 'iap'
export function getProducts(skus: string[]): Promise<Product<string>[]>;

It looks typeof getProducts is not valid for Android until the SkuType is nomalized.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks typeof getProducts is not valid for Android until the SkuType is nomalized.

I believe it is, 'inapp' is for Android and 'iap' for iOS.

Note that I split up Product and Subscription since getProducts only returns products (I think at some point in history it also included subscriptions on iOS πŸ€”)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about. Alright, If it's case insensitive. πŸ‘Œ

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's case insensitive, but index.js is using the lower case version so I assumed that that was the correct one πŸ‘

@LinusU
Copy link
Member Author

LinusU commented Aug 15, 2018

I removed RNVersion from here as well, my reasoning is that passing in undefined will actually work since undefined < 54 evaluates to false. Anyhow, when we merge #238 that parameter will be gone forever πŸŽ‰

Copy link
Member

@cometkim cometkim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks neat! great job @LinusU.

Made a few change requests and everything else LGTM.

'exclude-old-transactions'?: boolean
}

export interface ReceiptValidationResponse {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing is-retryable property.

is-retryable: Retry validation for this receipt. Only applicable to status codes 21100-21199 (listed in Table 2-1)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will make PR for this πŸ‘

}

export const SkuTypes: SkuTypes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's good plan. But breaks compatibility, so I think we'll have to deal with this change separately.

@hyochan
Copy link
Member

hyochan commented Aug 18, 2018

@cometkim @LinusU Thank for your work!

@hyochan hyochan merged commit ebac92a into dooboolab-community:master Aug 18, 2018
@cometkim
Copy link
Member

Hey @dooboolab and @LinusU, I was noticed about "Mapped types on tuples" support in TypeScript 3.1

It looks like we can make this declaration be exact and short, but should drop support below versions of TS.

export function getProducts<A extends string, B extends string, C extends string, D extends string, E extends string, F extends string>(skus: [A, B, C, D, E, F]): Promise<[Product<A>, Product<B>, Product<C>, Product<D>, Product<E>, Product<F>]>;
export function getProducts<A extends string, B extends string, C extends string, D extends string, E extends string>(skus: [A, B, C, D, E]): Promise<[Product<A>, Product<B>, Product<C>, Product<D>, Product<E>]>;
export function getProducts<A extends string, B extends string, C extends string, D extends string>(skus: [A, B, C, D]): Promise<[Product<A>, Product<B>, Product<C>, Product<D>]>;
export function getProducts<A extends string, B extends string, C extends string>(skus: [A, B, C]): Promise<[Product<A>, Product<B>, Product<C>]>;
export function getProducts<A extends string, B extends string>(skus: [A, B]): Promise<[Product<A>, Product<B>]>;
export function getProducts<A extends string>(skus: [A]): Promise<[Product<A>]>;
export function getProducts(skus: string[]): Promise<Product<string>[]>;

How do you think about?

@LinusU
Copy link
Member Author

LinusU commented Oct 19, 2018

[...] but should drop support below versions of TS.

works for me πŸ‘

@hyochan
Copy link
Member

hyochan commented Oct 20, 2018

@cometkim @LinusU Actually, I don't know how to manage this one since it isn't downward compatible. Would this be ok to just drop the lower version support?

@cometkim
Copy link
Member

@dooboolab It's not that important while it is not a dependency or peer dependency.

@cometkim
Copy link
Member

@LinusU I just tried to use tuple mapping, but keyof does not support explicit inference of arrays or tuple entries.. it looks always string | number | symbol and the number is incompatible with Product<ID extends string>.

Closed this topic..

@hyochan hyochan added the πŸ— enhancement New feature or request label Dec 20, 2018
index.d.ts Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
πŸ— enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants