For Typescript Users
mitter.io SDKs are compiled with typescript 3.0.3, but target typescript 2.7.+ Versions of typescript below 2.7 might work, but are not supported.
Type-matching functions
mitter.subscribeToPaylod(payload => {
if (payload['@type'] === 'NewMessagePayload') {
// The next line will throw an error, since the type of
// payload is MessagingPipelinePayload
console.log('New message', payload.message.textPayload)
} else {
// The next will not throw an error, since the callback
// argument is already typed to MessagingPipelinePayload
console.log('New payload', payload.globalPipelinePayloadId)
}
})
mitter.subscribeToPayload(payload => {
if (isNewMessagingPayload(payload)) {
// The next line is OK, since the isNewMessagingPayload is a type
// predicate, which tells the compiler that if true, then the
// argument (payload) was of type NewMessagingPayload
console.log('New message', payload.message.textPayload)
}
})API calls using clients
Last updated