Skip to content
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

refactor: Replaced explicit typings with auto generated ones #745

Merged
merged 20 commits into from
Apr 7, 2022

Conversation

ozayr-zaviar
Copy link
Contributor

@ozayr-zaviar ozayr-zaviar commented Feb 25, 2022

Summary

This SDK was originally javascript only. We had to add explicit typings in lib/index.d.ts to support typescript users. Now that it has been converted to typescript, we can safely remove lib/index.d.ts and autogenerate typings. This PR does exactly that. We also encountered some discrepancies with existing typings so we fixed those too.

Test plan

  • Manually tested thoroughly with typescript projects
  • All existing tests pass.

@coveralls
Copy link

coveralls commented Feb 25, 2022

Coverage Status

Coverage increased (+0.001%) to 97.185% when pulling 10fcd43 on uzair/lite-typings into 5d526bd on master.

@ozayr-zaviar ozayr-zaviar changed the title feat: Typing for lite module feat: Typing dependency moved to entry level modules Mar 9, 2022
Copy link
Contributor

@zashraf1985 zashraf1985 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good so far. Requested a few more changes

EventDispatcher,
DatafileOptions,
SDKOptions,
OptimizelyOptions,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SDKOptions and OptimizelyOptions are not needed to be exposed. Config is enough for external usage

eventTags: EventTags;
logEvent: Event;
}

/**
* Entry level Config Entities
*/
export interface SDKOptions {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you compare it with Config and remove it if not needed. this looks redundant and might not be needed anymore.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config and SDKOptions shares most of the same variables except for:

Config:

  1. Extra jsonSchemaValidator variable in interface.
  2. Instead of using LogLevel | string, uses union type on all LOG_LEVEL enums.

SDKOptions contains:

  1. Extra eventMaxQueueSize variable in interface.
  2. Extra isValidInstance variable in interface.

We should consider having a base interface both Config and SDKOptions extend.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for pointing these out. WE are consolidating these two types in to one because Config was exposed from the explicit typings while SDKOptions was being used in the actual code. We need to use one of those now because we are removing the explicit types. We will keep Config and remove SDKOptions because thats what was being exposed to typescript users. I have requested @ozayr-zaviar to add the missing variables mentioned in your comments.

@zashraf1985 zashraf1985 changed the title feat: Typing dependency moved to entry level modules refactor: Replaced explicit typings with auto generated ones Mar 24, 2022
@zashraf1985 zashraf1985 marked this pull request as ready for review March 24, 2022 21:08
@zashraf1985 zashraf1985 requested a review from a team as a code owner March 24, 2022 21:08
- fixed some lint warnings
- Added changelog
Copy link
Contributor

@zashraf1985 zashraf1985 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT! Great work @ozayr-zaviar

@zashraf1985
Copy link
Contributor

@opti-jnguyen It will be great if we can get your review on this whenever you find some time.

datafile?: string,
logger: LoggerFacade,
// TODO[OASIS-6649]: Don't use object type
// eslint-disable-next-line @typescript-eslint/ban-types
Copy link
Contributor

@opti-jnguyen opti-jnguyen Mar 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these comments left here intentionally?

Saw more instances of this comment left around but don't see the associated ticket #6649 in the OASIS JIRA Issues list for some reason.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://optimizely.atlassian.net/browse/OASIS-6649
This should be moved to the tech debt epic. This is something thats tricky to resolve

Copy link
Contributor

@zashraf1985 zashraf1985 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ozayr-zaviar I have a few more change request.

  1. Config should also export a jsonSchemaValidator just like OptimizelyOptions
  2. isValidInstance is not logically needed on Config. We were just using config to hold this value and pass on to Optimizely constructor instead of storing it in to a local variable in the entry point. Please fix this.
  3. Update copyright headers wherever applicable.

Copy link
Contributor

@zashraf1985 zashraf1985 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for cleaning up the typings mess. Great work @ozayr-zaviar

@zashraf1985 zashraf1985 merged commit 5e8d539 into master Apr 7, 2022
@zashraf1985 zashraf1985 deleted the uzair/lite-typings branch April 7, 2022 19:30

export function setLogLevel(level: enums.LOG_LEVEL | string): void;

export function createInstance(config: Config): Client;
Copy link

@Develliot Develliot Jul 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change as it can now be Client | null

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

Successfully merging this pull request may close these issues.

None yet

6 participants