Skip to content

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

Conversation

yavorona
Copy link
Contributor

@yavorona yavorona commented Jul 21, 2020

Summary

  • Convert event_tags_validator module from JS to TS
  • Revise user_profile_service_validator module

Test plan

  • Existing unit tests

@@ -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>'
Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

@yavorona yavorona Jul 24, 2020

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.

Strange, even after compiling, it still Cannot find module '@optimizely/optimizely-sdk'. 🤔 I will do more research on that.

Copy link
Contributor Author

@yavorona yavorona Jul 24, 2020

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 think unknown 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 {
Copy link
Contributor

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>'
Copy link
Contributor

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.

@yavorona yavorona removed their assignment Jul 29, 2020
@yavorona yavorona force-pushed the pnguen/convert-event-tags-validator-to-ts branch from e864140 to f94a323 Compare July 29, 2020 16:46
@mjc1283 mjc1283 merged commit 27288b3 into mcarroll/optimizely-sdk-typescript Jul 29, 2020
@mjc1283 mjc1283 deleted the pnguen/convert-event-tags-validator-to-ts branch July 29, 2020 23:07
yavorona added a commit that referenced this pull request Aug 1, 2020
Summary:

Convert event_tags_validator module from JS to TS
Revise user_profile_service_validator module

Test plan:

Existing unit tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants