-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
strict null checks refactor #2390
Conversation
"test": "cross-env TS_NODE_COMPILER_OPTIONS='{\"strictNullChecks\": false}' TZ=UTC NODE_ENV=test E2E_RUNNER=true mocha --timeout 10000 --require ts-node/register --exit --file e2e/setup.ts src/**/**/*.spec.ts", | ||
"test:e2e": "cross-env TS_NODE_COMPILER_OPTIONS='{\"strictNullChecks\": false}' TZ=UTC NODE_ENV=test E2E_RUNNER=true mocha --timeout 10000 --require ts-node/register --exit --file e2e/setup.ts e2e/**/*.e2e.ts src/**/*.e2e.ts" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to add this since I only enabled strictNullCheck
for API code and not tests for now (there is a lot of refactoring need to do there).
@@ -10,12 +10,12 @@ export class EmailJsHandler extends BaseHandler { | |||
} | |||
buildProvider(credentials: ICredentials, from?: string) { | |||
const config: IEmailJsConfig = { | |||
from, | |||
host: credentials.host, | |||
from: from as string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one will probably need a further refactoring for all the providers so we can specify what are the required fields per each provider. For now just used the as
workaround
@@ -89,15 +91,18 @@ export class ProcessSubscriber { | |||
}) | |||
); | |||
|
|||
const jobs: JobEntity[] = []; | |||
const jobs: Omit<JobEntity, '_id'>[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future probably better to refactor this into different types for creation and returned from dal. Will be using this workaround in some areas until then.
apps/api/src/app/events/usecases/process-subscriber/process-subscriber.usecase.ts
Outdated
Show resolved
Hide resolved
apiKey: credentials.apiKey as string, | ||
username: credentials.user as string, | ||
domain: credentials.domain as string, | ||
from: from as string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we have a duplication of all the provider factories on both API and application generic. didn't refactored it for now to avoid non strict null changes in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @scopsy!
You've caught and fixed so many bugs here! 🔥
We should merge this ASAP, because keeping it open will require a lot of effort
apps/api/src/app/events/usecases/process-subscriber/process-subscriber.usecase.ts
Outdated
Show resolved
Hide resolved
@@ -1,6 +1,7 @@ | |||
{ | |||
"extends": "../../tsconfig.json", | |||
"compilerOptions": { | |||
"strictNullChecks": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, I think that we should have it defined in the root tsconfig.base.json
, but I'm not sure if all packages use it... we should only redefine it in the tests like you did
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I first started as defining it for everything, unfortuently it was to much errors for me to handle. So I focused in this PR on the critical services. We will have to refactor it in the future to enable globally. Wdyt?
What?
This pull request introduces the "strictNullCheck" of typescript. This feature adds additional type-checking to the compiler and helps to prevent null and undefined values from being assigned to variables.
Why?
This PR mainly handles the needed refactoring for build to pass, further improved could be made and in some cases hacks been used to pass the build (for example usage of
as
).