In TypeScript, string is a primitive type, while String is a global object that is a wrapper around the primitive string type. We were using both of these interchangeably which could lead to issues like this -
let existingEmail = Klaviyo.getEmail(undefined);
Klaviyo.setProfile({
email: existingEmail, //this is an error: TS2322: Type String | null is not assignable to type string | undefined
});
The above error is because getEmail returns an instance of type String whereas setProfile accepts an instance of Profile whose email property is of type string.
The fix was to across the board using string instead of String. This in some cases could be a breaking change if developer made any provision in their code to handle this inconsistency. Since we are in beta we will release this change as a minor version update or roll it into our first major version release.
Check List
[ ] Are you changing anything with the public API?
[ ] Are your changes backwards compatible with previous SDK Versions?
Description
In TypeScript,
string
is a primitive type, whileString
is a global object that is a wrapper around the primitivestring
type. We were using both of these interchangeably which could lead to issues like this -The above error is because
getEmail
returns an instance of typeString
whereassetProfile
accepts an instance ofProfile
whose email property is of typestring
.The fix was to across the board using
string
instead ofString
. This in some cases could be a breaking change if developer made any provision in their code to handle this inconsistency. Since we are in beta we will release this change as a minor version update or roll it into our first major version release.Check List
Changelog / Code Overview
Test Plan
Related Issues/Tickets