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

Allow users to narrow down type #3

Open
BasixKOR opened this issue Feb 6, 2022 · 1 comment
Open

Allow users to narrow down type #3

BasixKOR opened this issue Feb 6, 2022 · 1 comment
Labels
can implement This feature or bug fix can be implemented

Comments

@BasixKOR
Copy link

BasixKOR commented Feb 6, 2022

Hi! Thank you for creating a great package. However, while using it, I noticed I couldn't narrow down the object types using standard TS type guards. For example, given an item: Track | Episode; I can't narrow it down to Track by simply checking item.type === "episode".

This happens because all interfaces share the same SpotifyType, which doesn't guarantee an Episode will always have a "episode" as a type.

Could we change them to simple literal types to benefit from type narrowing? I'd like to file a PR if you're interested.

@scientific-dev scientific-dev added the can implement This feature or bug fix can be implemented label Feb 6, 2022
@scientific-dev
Copy link
Member

I will work on this issue when i get some time. You can file a pr if you are interested too.

As for now, you can do it like this,

const track = item as Track;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can implement This feature or bug fix can be implemented
Projects
None yet
Development

No branches or pull requests

2 participants