Skip to content

Commit efcf044

Browse files
authored
chore: make it build with strict null checks set to true (#9554)
As part of preparation for ESM and node/TSC updates, this PR will make Unleash build with strictNullChecks set to true, since that's what's in our tsconfig file. Hence, this PR also removes the `--strictNullChecks false` flag in our compile tasks in package.json. TL;DR - Clean up your code rather than turning off compiler security features :)
1 parent d082e5e commit efcf044

File tree

118 files changed

+577
-310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+577
-310
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@
3535
"scripts": {
3636
"start": "TZ=UTC node ./dist/server.js",
3737
"copy-templates": "copyfiles -u 1 src/mailtemplates/**/* dist/",
38-
"build:backend": "tsc --pretty --strictNullChecks false",
38+
"build:backend": "tsc --pretty",
3939
"build:frontend": "yarn --cwd ./frontend run build",
4040
"build:frontend:if-needed": "./scripts/build-frontend-if-needed.sh",
4141
"build": "yarn run clean && concurrently \"yarn:copy-templates\" \"yarn:build:frontend\" \"yarn:build:backend\"",
42-
"dev:backend": "TZ=UTC NODE_ENV=development tsc-watch --strictNullChecks false --onSuccess \"node dist/server-dev.js\"",
42+
"dev:backend": "TZ=UTC NODE_ENV=development tsc-watch --onSuccess \"node dist/server-dev.js\"",
4343
"dev:frontend": "wait-on tcp:4242 && yarn --cwd ./frontend run dev",
4444
"dev:frontend:cloud": "UNLEASH_BASE_PATH=/demo/ yarn run dev:frontend",
4545
"dev": "concurrently \"yarn:dev:backend\" \"yarn:dev:frontend\"",
4646
"prepare:backend": "concurrently \"yarn:copy-templates\" \"yarn:build:backend\"",
47-
"start:dev": "yarn run clean && TZ=UTC NODE_ENV=development tsc-watch --strictNullChecks false --onSuccess \"node dist/server-dev.js\"",
47+
"start:dev": "yarn run clean && TZ=UTC NODE_ENV=development tsc-watch --onSuccess \"node dist/server-dev.js\"",
4848
"db-migrate": "db-migrate --migrations-dir ./src/migrations",
4949
"lint": "biome check .",
5050
"lint:fix": "biome check . --write",
5151
"local:package": "del-cli --force build && mkdir build && cp -r dist docs CHANGELOG.md LICENSE README.md package.json build",
52-
"build:watch": "yarn run clean && tsc -w --strictNullChecks false",
52+
"build:watch": "tsc -w",
5353
"prepare": "husky && yarn --cwd ./frontend install && if [ ! -d ./dist ]; then yarn build; fi",
5454
"test": "NODE_ENV=test PORT=4243 node --trace-warnings node_modules/.bin/jest",
5555
"test:unit": "NODE_ENV=test PORT=4243 jest --testPathIgnorePatterns=src/test/e2e --testPathIgnorePatterns=dist",
@@ -60,7 +60,7 @@
6060
"test:coverage": "NODE_ENV=test PORT=4243 jest --coverage --testLocationInResults --outputFile=\"coverage/report.json\" --forceExit",
6161
"test:coverage:jest": "NODE_ENV=test PORT=4243 jest --silent --ci --json --coverage --testLocationInResults --outputFile=\"report.json\" --forceExit",
6262
"test:updateSnapshot": "NODE_ENV=test PORT=4243 jest --updateSnapshot",
63-
"seed:setup": "ts-node --compilerOptions '{\"strictNullChecks\": false}' src/test/e2e/seed/segment.seed.ts",
63+
"seed:setup": "ts-node src/test/e2e/seed/segment.seed.ts",
6464
"seed:serve": "UNLEASH_DATABASE_NAME=unleash_test UNLEASH_DATABASE_SCHEMA=seed yarn run start:dev",
6565
"clean": "del-cli --force dist",
6666
"heroku-postbuild": "cd frontend && yarn && yarn build",
@@ -220,7 +220,7 @@
220220
"supertest": "7.0.0",
221221
"ts-node": "10.9.2",
222222
"tsc-watch": "6.2.1",
223-
"typescript": "5.4.5",
223+
"typescript": "5.8.2",
224224
"wait-on": "^7.2.0"
225225
},
226226
"resolutions": {

src/lib/addons/datadog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ interface DDRequestBody {
3232
export default class DatadogAddon extends Addon {
3333
private msgFormatter: FeatureEventFormatter;
3434

35-
flagResolver: IFlagResolver;
35+
declare flagResolver: IFlagResolver;
3636

3737
constructor(config: IAddonConfig) {
3838
super(definition, config);

src/lib/addons/new-relic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ interface INewRelicRequestBody {
3939
export default class NewRelicAddon extends Addon {
4040
private msgFormatter: FeatureEventFormatter;
4141

42-
flagResolver: IFlagResolver;
42+
declare flagResolver: IFlagResolver;
4343

4444
constructor(config: IAddonConfig) {
4545
super(definition, config);

src/lib/addons/slack-app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ interface ISlackAppAddonParameters {
3434
export default class SlackAppAddon extends Addon {
3535
private msgFormatter: FeatureEventFormatter;
3636

37-
flagResolver: IFlagResolver;
37+
declare flagResolver: IFlagResolver;
3838

3939
private accessToken?: string;
4040

src/lib/addons/slack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface ISlackAddonParameters {
2525
export default class SlackAddon extends Addon {
2626
private msgFormatter: FeatureEventFormatter;
2727

28-
flagResolver: IFlagResolver;
28+
declare flagResolver: IFlagResolver;
2929

3030
constructor(args: IAddonConfig) {
3131
super(slackDefinition, args);

src/lib/addons/teams.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ interface ITeamsParameters {
3838
export default class TeamsAddon extends Addon {
3939
private msgFormatter: FeatureEventFormatter;
4040

41-
flagResolver: IFlagResolver;
41+
declare flagResolver: IFlagResolver;
4242

4343
constructor(args: IAddonConfig) {
4444
if (args.flagResolver.isEnabled('teamsIntegrationChangeRequests')) {

src/lib/addons/webhook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface IParameters {
2525
export default class Webhook extends Addon {
2626
private msgFormatter: FeatureEventFormatter;
2727

28-
flagResolver: IFlagResolver;
28+
declare flagResolver: IFlagResolver;
2929

3030
constructor(args: IAddonConfig) {
3131
super(definition, args);

src/lib/app.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ jest.mock(
1818
},
1919
);
2020

21-
const getApp = require('./app').default;
22-
21+
import getApp from './app';
2322
test('should not throw when valid config', async () => {
2423
const config = createTestConfig();
24+
// @ts-expect-error - We're passing in empty stores and services
2525
const app = await getApp(config, {}, {});
2626
expect(typeof app.listen).toBe('function');
2727
});
@@ -33,6 +33,7 @@ test('should call preHook', async () => {
3333
called++;
3434
},
3535
});
36+
// @ts-expect-error - We're passing in empty stores and services
3637
await getApp(config, {}, {});
3738
expect(called).toBe(1);
3839
});
@@ -44,6 +45,7 @@ test('should call preRouterHook', async () => {
4445
called++;
4546
},
4647
});
48+
// @ts-expect-error - We're passing in empty stores and services
4749
await getApp(config, {}, {});
4850
expect(called).toBe(1);
4951
});
@@ -82,6 +84,7 @@ describe('compression middleware', () => {
8284
disableCompression: disableCompression as any,
8385
},
8486
});
87+
// @ts-expect-error - We're passing in empty stores and services
8588
await getApp(config, {}, {});
8689
expect(compression).toBeCalledTimes(+expectCompressionEnabled);
8790
},

src/lib/app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ export default async function getApp(
195195
}
196196

197197
// Setup API routes
198+
// @ts-expect-error - our db is possibly undefined and our indexrouter doesn't currently handle that
198199
app.use(`${baseUriPath}/`, new IndexRouter(config, services, db).router);
199200

200201
if (process.env.NODE_ENV !== 'production') {

src/lib/create-config.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -335,17 +335,22 @@ const parseEnvVarInitialAdminUser = (): UsernameAdminUser | undefined => {
335335
return username && password ? { username, password } : undefined;
336336
};
337337

338-
const defaultAuthentication: IAuthOption = {
339-
demoAllowAdminLogin: parseEnvVarBoolean(
340-
process.env.AUTH_DEMO_ALLOW_ADMIN_LOGIN,
341-
false,
342-
),
343-
enableApiToken: parseEnvVarBoolean(process.env.AUTH_ENABLE_API_TOKEN, true),
344-
type: authTypeFromString(process.env.AUTH_TYPE),
345-
customAuthHandler: defaultCustomAuthDenyAll,
346-
createAdminUser: true,
347-
initialAdminUser: parseEnvVarInitialAdminUser(),
348-
initApiTokens: [],
338+
const buildDefaultAuthOption = () => {
339+
return {
340+
demoAllowAdminLogin: parseEnvVarBoolean(
341+
process.env.AUTH_DEMO_ALLOW_ADMIN_LOGIN,
342+
false,
343+
),
344+
enableApiToken: parseEnvVarBoolean(
345+
process.env.AUTH_ENABLE_API_TOKEN,
346+
true,
347+
),
348+
type: authTypeFromString(process.env.AUTH_TYPE),
349+
customAuthHandler: defaultCustomAuthDenyAll,
350+
createAdminUser: true,
351+
initialAdminUser: parseEnvVarInitialAdminUser(),
352+
initApiTokens: [],
353+
};
349354
};
350355

351356
const defaultImport: WithOptional<IImportOption, 'file'> = {
@@ -563,7 +568,7 @@ export function createConfig(options: IUnleashOptions): IUnleashConfig {
563568
const initApiTokens = loadInitApiTokens();
564569

565570
const authentication: IAuthOption = mergeAll([
566-
defaultAuthentication,
571+
buildDefaultAuthOption(),
567572
(options.authentication
568573
? removeUndefinedKeys(options.authentication)
569574
: options.authentication) || {},

0 commit comments

Comments
 (0)