braze-inc / braze-web-sdk

Public repo for the Braze Web SDK
https://www.braze.com
Other
71 stars 25 forks source link

[Feature]: Cannot distinguish ControlMessage | InAppMessage #143

Closed FourwingsY closed 1 year ago

FourwingsY commented 1 year ago

What problem are you facing?

function isControlMessage(message: InAppMessage | ControlMessage): message is ControlMessage {
  return message.isControl === true
  // or whatever 
  // return message instanceof ControlMessage
}

This function does not works.

Workarounds

The main problem is ControlMessage is absolute subset of InAppMessage

So, making small difference with it will makes typescript distinguish between them.

Ideal Solution

While I tried some tests in TS playground, this fix will make it work.

class ControlMessage {
  ...
  isControl: true // from boolean
}

Other Information

No response

wesleyorbin commented 1 year ago

Hi @FourwingsY. Thanks for bringing this to our attention. We'll include this in our next release.

spvismaya commented 1 year ago

Hi @FourwingsY , we have included this in our most recent SDK release v4.8.1. Thanks again!