-
Notifications
You must be signed in to change notification settings - Fork 83
feat: Convert event_tags_validator module to TS #528
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
feat: Convert event_tags_validator module to TS #528
Conversation
@@ -30,6 +30,8 @@ const MODULE_NAME = 'USER_PROFILE_SERVICE_VALIDATOR'; | |||
* @return {boolean} true if the instance is valid | |||
* @throws If the instance is not valid | |||
*/ | |||
|
|||
//TODO: Use defined UserProfileService interface instead of 'Record<string, unknown>' |
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.
UserProfileService
interface is declared in '@optimizely/optimizely-sdk' molude in index.d.ts
, so I tried importing it with
{ UserProfileService } from '@optimizely/optimizely-sdk'
and also import { UserProfileService } from '../../index'
, which did not work. Any suggestions on how to import it would be much appreciated! @mjc1283 @mikeng13
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.
Hmm yeah I think we'll have to do something a little more drastic. Like the UserProfileService interface needs to be defined in one of the .ts
files, maybe it can be its own file under plugins
and then the top level index.d.ts
would import that interface and re-export. @mjc1283 wdyt?
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.
For me, import { UserProfileService } from '@optimizely/optimizely-sdk';
works, @yavorona we can dig to this to figure out what's wrong. Maybe it's related to IDE configuration? I was able to get it to compile with npm run build
.
But in any case, I don't think we want to use that UserProfileService
type here. Again I think unknown
is what we need, treating this as an unvalidated value (the user could have passed in anything).
@mikeng13
Like the UserProfileService interface needs to be defined in one of the .ts files, maybe it can be its own file under plugins and then the top level index.d.ts would import that interface and re-export.
I think this will work. We could only export types at the top level that consumers would need, so not everything.
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.
For me,
import { UserProfileService } from '@optimizely/optimizely-sdk';
works, @yavorona we can dig to this to figure out what's wrong. Maybe it's related to IDE configuration? I was able to get it to compile withnpm run build
.
Strange, even after compiling, it still Cannot find module '@optimizely/optimizely-sdk'
. 🤔 I will do more research on that.
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.
But in any case, I don't think we want to use that
UserProfileService
type here. Again I thinkunknown
is what we need, treating this as an unvalidated value (the user could have passed in anything).
Changing it to unknown
produces TSError: ⨯ Unable to compile TypeScript:
for both if (typeof userProfileServiceInstance.lookup !== 'function') {...}
and else if (typeof userProfileServiceInstance.save !== 'function') {...}
. any
in this case works though, so it might make sense to use it here. @mjc1283 what do you think?
* @throws If event tags are not valid | ||
*/ | ||
export var validate = function(eventTags) { | ||
export function validate(eventTags: EventTags): boolean { |
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 think the right type for eventTags
is unknown
. This is a value passed in by the user of unknown type.
@@ -30,6 +30,8 @@ const MODULE_NAME = 'USER_PROFILE_SERVICE_VALIDATOR'; | |||
* @return {boolean} true if the instance is valid | |||
* @throws If the instance is not valid | |||
*/ | |||
|
|||
//TODO: Use defined UserProfileService interface instead of 'Record<string, unknown>' |
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.
For me, import { UserProfileService } from '@optimizely/optimizely-sdk';
works, @yavorona we can dig to this to figure out what's wrong. Maybe it's related to IDE configuration? I was able to get it to compile with npm run build
.
But in any case, I don't think we want to use that UserProfileService
type here. Again I think unknown
is what we need, treating this as an unvalidated value (the user could have passed in anything).
@mikeng13
Like the UserProfileService interface needs to be defined in one of the .ts files, maybe it can be its own file under plugins and then the top level index.d.ts would import that interface and re-export.
I think this will work. We could only export types at the top level that consumers would need, so not everything.
e864140
to
f94a323
Compare
Summary: Convert event_tags_validator module from JS to TS Revise user_profile_service_validator module Test plan: Existing unit tests
Summary
event_tags_validator
module from JS to TSuser_profile_service_validator
moduleTest plan