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

Change TS types to use type declarations from PN JS SDK #155

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

wkal-pubnub
Copy link
Contributor

(instead of community driven @types/pubnub)

@wkal-pubnub wkal-pubnub requested a review from parfeon January 9, 2025 11:11
@wkal-pubnub wkal-pubnub marked this pull request as ready for review January 9, 2025 11:11
src/jsMain/resources/index.d.ts Outdated Show resolved Hide resolved
src/jsMain/resources/index.d.ts Outdated Show resolved Hide resolved
src/jsMain/resources/index.d.ts Outdated Show resolved Hide resolved
userMetadata?: {
[key: string]: any;
};
};
type MessageDTOParams = PubNub.FetchMessagesResponse["channels"]["channel"][0] | EnhancedMessageEvent;
type MessageDTOParams = History.FetchMessagesResponse["channels"]["channel"][0] | EnhancedMessageEvent;
Copy link

Choose a reason for hiding this comment

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

Suggested change
type MessageDTOParams = History.FetchMessagesResponse["channels"]["channel"][0] | EnhancedMessageEvent;
type MessageDTOParams = History.FetchMessagesForChannelsResponse['channels'][string][number] | History.FetchMessagesWithActionsResponse['channels'][string][number] | EnhancedMessageEvent;

I don't know where it used, just assuming what it expected to reflect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just checking that I should change [0] to [number] ? (I don't know TS types that well so wanted to make sure it's not a mistake)

Copy link

Choose a reason for hiding this comment

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

Because there is actually no array, we are speaking about type declaration. With this annotation, we are telling TS that we need the type of the single entry for the array of messages for channel name stored as a string.
Sadly, we have to use explicit types which have been unified under FetchMessagesResponse because TS will end up with specifying any because it can't figure out :/

src/jsMain/resources/index.d.ts Outdated Show resolved Hide resolved
src/jsMain/resources/index.d.ts Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants