-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Enables strict null checks in SDK #2360
base: main
Are you sure you want to change the base?
Conversation
@@ -302,7 +302,7 @@ function AdditionalFormFields({ | |||
disabled={isLoading} | |||
/> | |||
{errors[field.name] && ( | |||
<FormError>{errors[field.name].message}</FormError> | |||
<FormError>{errors[field.name]!.message}</FormError> |
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'm not sure why this is needed since we have the check errors[field.name] && (
?
@@ -69,7 +69,7 @@ async function getAuthUserData(userId: {= userEntityUpper =}['id']): Promise<Aut | |||
throwInvalidCredentialsError() | |||
} | |||
|
|||
return createAuthUserData(user); | |||
return createAuthUserData(user!); |
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.
Again, I'm not sure why this is needed since we have the check if (!user) {
. Maybe it's not obvious to the compiler that the throwInvalidCredentialsError
fn throws?
const { data: task, isLoading } = tasksCrud.get.useQuery({ | ||
id: parseInt(id, 10), | ||
}); | ||
const { id } = useParams<{ id: 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.
Not related to this PR, but a quick fix since id
is of type string | undefined
.
@@ -18,7 +18,7 @@ import { | |||
// Details here: https://github.com/wasp-lang/wasp/issues/2017 | |||
export function makeQueryCacheKey<Input, Output>( | |||
query: Query<Input, Output>, | |||
payload: Input | |||
payload?: Input |
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.
payload !== undefined
hints at payload
being optional
@@ -1,9 +1,9 @@ | |||
{{={= =}=}} |
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've started to work on enabling strict null checks while working on env variables, so these are some changes I left from that effort - env
-> nodeEnv
since I imagined that the import of env vars would look like import { env } from 'wasp/server'
@@ -93,4 +93,5 @@ type ClientOperationWithNonAnyInput<Input, Output> = | |||
? (args?: unknown) => Promise<Output> | |||
: [Input] extends [void] | |||
? () => Promise<Output> | |||
: (args: Input) => Promise<Output> | |||
// TODO: decide if this is what we want? | |||
: (args?: Input) => Promise<Output> |
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.
We get the error:
client/operations/hooks.ts(32,26): error TS2345: Argument of type 'Input | undefined' is not assignable to parameter of type 'Input'.
The useQuery
hook definition:
function useQuery<Input, Output>(
query: Query<Input, Output>,
queryFnArgs?: Input,
options?: any
): UseQueryResult<Output, Error>
has the queryFnArgs
as an optional argument: and it executes query(queryFnArgs)
, query
is:
query: Query<Input, Output>
which is in the end (args: Input) => Promise<Output>
.
This leads me to set the args
as optional here.
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.
@sodic alternativelly, I can just put a @ts-ignore
and not modify anything related to operations, so we can deal with this in the future?
18f9fd0
to
a509762
Compare
This PR enables
strictNullChecks
option in the SDKtsconfig.json
.We want to enable this option to make sure Zod schemas are working properly before we start using them for env variables validation.
Left to do
@ts-ignore
and a TODO for things that need more workUsing
@ts-ignore
is not that problematic since it will unblock us for using Zod schemas, but also explicitly mark parts of the code base that need some work. This work was still needed before this PR, but it was implicit.