Skip to content

Conversation

@yavorona
Copy link
Contributor

@yavorona yavorona commented Nov 9, 2020

Summary

This pr created in response to sdk issue #613
The steps to reproduce and fix the issues were:

  • comment out"suppressImplicitAnyIndexErrors": true in TSConfig
  • fix type error issues as shown below.

Test plan

Existing FSC and unit tests

@yavorona yavorona requested a review from a team as a code owner November 9, 2020 23:28
@yavorona yavorona removed their assignment Nov 9, 2020
@coveralls
Copy link

coveralls commented Nov 9, 2020

Coverage Status

Coverage increased (+0.003%) to 96.71% when pulling a7208bb on pnguen/fix-type-errors into a0157fd on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.001%) to 96.707% when pulling 92c8674 on pnguen/fix-type-errors into e0158e5 on master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.001%) to 96.707% when pulling 92c8674 on pnguen/fix-type-errors into e0158e5 on master.

tsconfig.json Outdated
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
"suppressImplicitAnyIndexErrors": true,
// "suppressImplicitAnyIndexErrors": true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's delete it.

}
Object.keys(stringInputs).forEach(key => {
if (!stringValidator.validate(stringInputs[key])) {
if (!stringValidator.validate(stringInputs[key as keyof unknown])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems better to define 'feature_key' | 'user_id' | 'variable_key' | 'experiment_key' | 'event_key' as a type, then coerce key to that. I'm not sure what keyof unknown means. I thought keyof was only to be used on object types or types with index signatures.

if (typeof attributes === 'object' && !Array.isArray(attributes) && attributes !== null) {
Object.keys(attributes).forEach(function(key) {
if (typeof attributes[key] === 'undefined') {
if (typeof attributes[key as keyof unknown] === 'undefined') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment about keyof unknown. If we really want to do this, let's add a comment at least explaining what keyof unknown is doing. Alternatively we could coerce attributes to { [key: string]: unknown }, then we could index it with key. IMO this would be more verbose but clearer.

@yavorona yavorona self-assigned this Nov 10, 2020
@yavorona yavorona force-pushed the pnguen/fix-type-errors branch from 28ceb19 to c0af81f Compare November 12, 2020 18:05
@yavorona yavorona removed their assignment Nov 12, 2020
Copy link
Contributor

@mjc1283 mjc1283 left a comment

Choose a reason for hiding this comment

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

LGTM. I added a few suggestions. Thanks for fixing this.

Comment on lines 65 to 67
export type InputKey = 'feature_key' | 'user_id' | 'variable_key' | 'experiment_key' | 'event_key' | 'variation_id';

export type StringInputs = Partial<Record<InputKey, unknown>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these only used in lib/optimizely.ts? Not sure they need to be in shared_types.

Comment on lines 37 to 40
const errorHandler = (config as { [key: string]: unknown })['errorHandler'];
const eventDispatcher = (config as { [key: string]: unknown })['eventDispatcher'];
const logger = (config as { [key: string]: unknown })['logger'];
if (errorHandler && typeof (errorHandler as { [key: string]: unknown })['handleError'] !== 'function') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe try this to make it less verbose:

config = config as { [key: string]: unknown };

Copy link
Contributor Author

@yavorona yavorona Nov 13, 2020

Choose a reason for hiding this comment

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

It would work only if I assign it to a new variable.
Since we are using { [key: string]: unknown } to avoid these type errors, I think it would make sense to save this type in shared_types as ObjectWithUnknownProperties. WDYT @mjc1283

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. If we need it in several modules, it makes sense to define it in shared_types.

@yavorona yavorona force-pushed the pnguen/fix-type-errors branch from b3b3917 to 15ec3c5 Compare November 16, 2020 23:31
@yavorona yavorona merged commit 1c25d23 into master Nov 17, 2020
@yavorona yavorona deleted the pnguen/fix-type-errors branch November 17, 2020 18:53
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.

4 participants