-
Notifications
You must be signed in to change notification settings - Fork 985
Remove @firebase/messaging-types #816
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
Conversation
| deleteToken(token: string): Promise<boolean>; | ||
| getToken(): Promise<string | null>; | ||
| onMessage( | ||
| // tslint:disable-next-line no-any The message payload can be anything. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't object the better type for "I have no idea what this is, but I don't do anything specific with it"? And that's what the implementation seems to use anyway?
| nextOrObserver: NextFn<object> | Observer<object>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation uses object because inside the SDK we don't (and shouldn't) access any properties of the payload. Like you said, we don't do anything specific with it.
The exported types are different, because the user should know and be able to access their payload's properties.
So this would work with any and wouldn't work with object (when --strict flag is on, because of strictFunctionTypes):
messaging.onMessage((payload: UserDefinedPayloadObjectType) => {
const messageData = payload.someField;
// Do stuff with payload.
});
I'm planning on eventually making this a MessagePayload and preventing the --strict errors, but I'm about to propose some changes to that type, so I think it's better to keep this as any for now and change it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, the type safety escape hatch is used because this isn't type safe, gotcha :/
Seems to me like the whole FirebaseMessaging interface should take a type parameter of the expected type, and then callers are expected to provide callbacks that handle precisely that type. In the meantime, carry on I guess :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate what you are doing here. The point of the *-types packages was to allow components external to messaging to take direct dependencies on a components types w/o having to reference the actual implementation itself.
When we have done the work to better create ES Modules for our firebase components, then I think we can investigate this route a bit more. Until then, I don't think we can merge this.
|
The external components (in this case, |
|
It's not sizing I'm concerned about at all. We want a standard for our internal component devs looking to reference an interface from another component (the actual interface, not the implementation itself). The |
|
Then I don't see any reason not to make the |
|
While in principle that would work, in practice we also want to be able to version these interfaces independently from their implementations (so components can know if they are going to be broken by a change in the types). If we bake the two into the As I mentioned, once we have gone down the module path with our components (so we aren't patching |
|
Components don't get broken by changes in types, types let the component developers know that the implementation changed and their code is broken. If the types change, and their code isn't compatible with the new types, TS will let them know. That is the benefit of using TypeScript. I don't see why anyone would need separate versions for types, or would want the types to be incompatible with the implementation, which is possible if types and implementation are imported from different packages. |
Moves messaging types to an interface within the messaging package. Closes #526.
a6a7b16 to
0f4e400
Compare
|
I'm going to close this per our conversation. Let's revisit later. |
Moves messaging types to an interface within the messaging package.
Closes #526.