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

Messaging interface BaseMessage is no longer exported #1184

Closed
rubenvereecken opened this issue Mar 3, 2021 · 7 comments
Closed

Messaging interface BaseMessage is no longer exported #1184

rubenvereecken opened this issue Mar 3, 2021 · 7 comments
Assignees

Comments

@rubenvereecken
Copy link

I just upgraded to 7.5.0coming from 7.2.1. I just noticed I could no longer import the BaseMessage interface, which I use because I've got some functionality that is independent of the exact type of Message. It looks like the interface is no longer exported. Is this on purpose? I had a look at where this was taken out but I struggled navigating the git blame on Github.

interface BaseMessage {

@google-oss-bot
Copy link

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@lahirumaramba
Copy link
Member

Hi @rubenvereecken! Thank you for reporting this issue.

@hiranya911 should we export BaseMessage along with the rest we did in #1147 ?

@hiranya911
Copy link
Contributor

BaseMessage was never intended to be part of our public API surface. In the old releases it was declared outside of the admin.messaging namespace to keep it separate from the public API:

type BaseMessage = {
data?: {[key: string]: string};
notification?: admin.messaging.Notification;
android?: admin.messaging.AndroidConfig;
webpush?: admin.messaging.WebpushConfig;
apns?: admin.messaging.ApnsConfig;
};

In more recent versions it is in the namespace, but is not exported:

interface BaseMessage {
data?: { [key: string]: string };
notification?: Notification;
android?: AndroidConfig;
webpush?: WebpushConfig;
apns?: ApnsConfig;
fcmOptions?: FcmOptions;
}

@rubenvereecken can you use the Message type for your use case? Most things that that can be assigned to BaseMessage can be assigned to Message.

Also, can you please verify your SDK versions? We have never released a 7.2.1 or a 7.5.0.

@rubenvereecken
Copy link
Author

... I think I meant 9.2.1 and 9.5.0 as I seem to have 9.5.0 installed currently.

My current solution to get this working consists of using TokenMessage | MulticastMessage, pretty close to using Message which I noticed is a union type. The problem is that TokenMessage for example requires the token field, which I currently simply set to null until it gets populated later, if indeed it does. I used to use BaseMessage because I've got some generic functionality that fills in a bunch of basic fields. Only afterwards does the object become a TokenMessage or MulticastMessage, depending on what I need. Maybe this is unorthodox use of typing because I "upgrade" an object from one type to another.

@hiranya911
Copy link
Contributor

You can probably do something like this:

type MyBaseMessage = Partial<TokenMessage | MulticastMessage>

function addCommonFields(m: MyBaseMessage) {
  
}

const m = { };
addCommonFields(m);

const tm: TokenMessage = {...m, token: 'token'};
const mm: MulticastMessage = {...m, tokens: ['token']};

@rubenvereecken
Copy link
Author

rubenvereecken commented Mar 4, 2021

Actually, that's right, I'm very happy with that solution. Thanks @hiranya911!

Happy to close it here.

@hiranya911
Copy link
Contributor

Glad to hear that @rubenvereecken. We can also revisit the issue of exposing BaseMessage once our new modular API surface (on going effort), is a bit more fleshed out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants