Skip to content

Commit 3af7157

Browse files
authored
chore: tsc enable strict type checks (#132)
* chore: tsc enable `strict` type checks * fix types * more fixes * readme reword
1 parent daabd57 commit 3af7157

10 files changed

+36
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Eppo JS Common SDK for library
1+
# Common library for Eppo's JavasScript SDK
22

33
[![](https://img.shields.io/npm/v/@eppo/js-client-sdk-common)](https://www.npmjs.com/package/@eppo/js-client-sdk-common)
44
[![](https://img.shields.io/static/v1?label=GitHub+Pages&message=API+reference&color=00add8)](https://eppo-exp.github.io/js-client-sdk/js-client-sdk-common.html)

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,6 @@
7272
"md5": "^2.3.0",
7373
"pino": "^8.19.0",
7474
"semver": "^7.5.4"
75-
}
75+
},
76+
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
7677
}

src/bandit-evaluator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export interface BanditEvaluation {
2020
}
2121

2222
export class BanditEvaluator {
23-
private assignmentShards = BANDIT_ASSIGNMENT_SHARDS; // We just hard code this for now
24-
private sharder: Sharder = new MD5Sharder();
23+
private readonly assignmentShards = BANDIT_ASSIGNMENT_SHARDS; // We just hard code this for now
24+
private readonly sharder: Sharder = new MD5Sharder();
2525

2626
public evaluateBandit(
2727
flagKey: string,

src/client/eppo-client-assignment-details.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { MemoryOnlyConfigurationStore } from '../configuration-store/memory.stor
99
import { AllocationEvaluationCode } from '../flag-evaluation-details-builder';
1010
import { Flag, ObfuscatedFlag, Variation, VariationType } from '../interfaces';
1111
import { OperatorType } from '../rules';
12+
import { AttributeType } from '../types';
1213

1314
import EppoClient, { IAssignmentDetails } from './eppo-client';
1415
import { initConfiguration } from './test-utils';
@@ -323,7 +324,12 @@ describe('EppoClient get*AssignmentDetails', () => {
323324
[VariationType.STRING]: client.getStringAssignmentDetails.bind(client),
324325
[VariationType.JSON]: client.getJSONAssignmentDetails.bind(client),
325326
};
326-
const assignmentFn = typeAssignmentDetailsFunctions[variationType];
327+
const assignmentFn = typeAssignmentDetailsFunctions[variationType] as (
328+
flagKey: string,
329+
subjectKey: string,
330+
subjectAttributes: Record<string, AttributeType>,
331+
defaultValue: boolean | string | number | object,
332+
) => IAssignmentDetails<boolean | string | number | object>;
327333
if (!assignmentFn) {
328334
throw new Error(`Unknown variation type: ${variationType}`);
329335
}

src/client/eppo-client.spec.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { IConfigurationStore } from '../configuration-store/configuration-store'
1717
import { MemoryOnlyConfigurationStore } from '../configuration-store/memory.store';
1818
import { MAX_EVENT_QUEUE_SIZE, DEFAULT_POLL_INTERVAL_MS, POLL_JITTER_PCT } from '../constants';
1919
import { Flag, ObfuscatedFlag, VariationType } from '../interfaces';
20+
import { AttributeType } from '../types';
2021

2122
import EppoClient, { FlagConfigurationRequestParameters, checkTypeMatch } from './eppo-client';
2223
import { initConfiguration } from './test-utils';
@@ -214,7 +215,12 @@ describe('EppoClient E2E test', () => {
214215
[VariationType.JSON]: client.getJSONAssignment.bind(client),
215216
};
216217

217-
const assignmentFn = typeAssignmentFunctions[variationType];
218+
const assignmentFn = typeAssignmentFunctions[variationType] as (
219+
flagKey: string,
220+
subjectKey: string,
221+
subjectAttributes: Record<string, AttributeType>,
222+
defaultValue: boolean | string | number | object,
223+
) => never;
218224
if (!assignmentFn) {
219225
throw new Error(`Unknown variation type: ${variationType}`);
220226
}
@@ -258,7 +264,12 @@ describe('EppoClient E2E test', () => {
258264
[VariationType.JSON]: client.getJSONAssignment.bind(client),
259265
};
260266

261-
const assignmentFn = typeAssignmentFunctions[variationType];
267+
const assignmentFn = typeAssignmentFunctions[variationType] as (
268+
flagKey: string,
269+
subjectKey: string,
270+
subjectAttributes: Record<string, AttributeType>,
271+
defaultValue: boolean | string | number | object,
272+
) => never;
262273
if (!assignmentFn) {
263274
throw new Error(`Unknown variation type: ${variationType}`);
264275
}

src/client/eppo-client.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ export default class EppoClient {
515515
);
516516
evaluationDetails.banditAction = action;
517517
}
518-
} catch (err) {
518+
} catch (err: any) {
519519
logger.error('Error determining bandit action', err);
520520
if (!this.isGracefulFailureMode) {
521521
throw err;
@@ -752,7 +752,7 @@ export default class EppoClient {
752752
expectedVariationType,
753753
);
754754
return this.parseVariationWithDetails(result, defaultValue, expectedVariationType);
755-
} catch (error) {
755+
} catch (error: any) {
756756
const eppoValue = this.rethrowIfNotGraceful(error, defaultValue);
757757
if (error instanceof FlagEvaluationError && error.flagEvaluationDetails) {
758758
return {
@@ -790,7 +790,7 @@ export default class EppoClient {
790790
eppoValue: EppoValue.valueOf(result.variation.value, expectedVariationType),
791791
flagEvaluationDetails: result.flagEvaluationDetails,
792792
};
793-
} catch (error) {
793+
} catch (error: any) {
794794
const eppoValue = this.rethrowIfNotGraceful(error, defaultValue);
795795
return {
796796
eppoValue,
@@ -1010,7 +1010,7 @@ export default class EppoClient {
10101010
eventsToFlush.forEach((event) => {
10111011
try {
10121012
logFunction(event);
1013-
} catch (error) {
1013+
} catch (error: any) {
10141014
logger.error(`[Eppo SDK] Error flushing event to logger: ${error.message}`);
10151015
}
10161016
});
@@ -1057,7 +1057,7 @@ export default class EppoClient {
10571057
allocationKey: allocationKey ?? '__eppo_no_allocation',
10581058
variationKey: variation?.key ?? '__eppo_no_variation',
10591059
});
1060-
} catch (error) {
1060+
} catch (error: any) {
10611061
logger.error(`[Eppo SDK] Error logging assignment event: ${error.message}`);
10621062
}
10631063
}

src/evaluator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface FlagEvaluation {
3232
}
3333

3434
export class Evaluator {
35-
sharder: Sharder;
35+
private readonly sharder: Sharder;
3636

3737
constructor(sharder?: Sharder) {
3838
this.sharder = sharder ?? new MD5Sharder();
@@ -133,7 +133,7 @@ export class Evaluator {
133133
'No allocations matched. Falling back to "Default Allocation", serving NULL',
134134
),
135135
);
136-
} catch (err) {
136+
} catch (err: any) {
137137
const flagEvaluationDetails = flagEvaluationDetailsBuilder.gracefulBuild(
138138
'ASSIGNMENT_ERROR',
139139
`Assignment Error: ${err.message}`,

src/http-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default class FetchHttpClient implements IHttpClient {
6161
throw new HttpRequestError('Failed to fetch data', response?.status);
6262
}
6363
return await response.json();
64-
} catch (error) {
64+
} catch (error: any) {
6565
if (error.name === 'AbortError') {
6666
throw new HttpRequestError('Request timed out', 408, error);
6767
} else if (error instanceof HttpRequestError) {

src/poller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default function initPoller(
4848
startRequestSuccess = true;
4949
previousPollFailed = false;
5050
logger.info('Eppo SDK successfully requested initial configuration');
51-
} catch (pollingError) {
51+
} catch (pollingError: any) {
5252
previousPollFailed = true;
5353
logger.warn(
5454
`Eppo SDK encountered an error with initial poll of configurations: ${pollingError.message}`,
@@ -116,7 +116,7 @@ export default function initPoller(
116116
previousPollFailed = false;
117117
logger.info('Eppo SDK poll successful; resuming normal polling');
118118
}
119-
} catch (error) {
119+
} catch (error: any) {
120120
previousPollFailed = true;
121121
logger.warn(`Eppo SDK encountered an error polling configurations: ${error.message}`);
122122
const maxTries = 1 + (options?.maxPollRetries ?? DEFAULT_POLL_CONFIG_REQUEST_RETRIES);

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"target": "es2017",
99
"outDir": "dist",
1010
"noImplicitAny": true,
11-
"strictNullChecks": true,
11+
"strict": true,
1212
"strictPropertyInitialization": true
1313
},
1414
"include": ["src/**/*.ts"],

0 commit comments

Comments
 (0)