TypedSQL: Passing null values into raw SQL?
I am currently using an aggregate query that returns a boolean that is either true or false if some user (current user) has reacted to a given post. Here is the query (thanks Jon Harrell--if the code has issues it's likely because I've been modifying it):
And I want to be able to pass a null
userId
value if there is no current user into but unfortunately this does not work with the type error Argument of type 'string | null | undefined' is not assignable to parameter of type 'string'. Type 'undefined' is not assignable to type 'string'.ts(2345)
Up until now, I've been passing two functions conditionally when userId is not known:
But this doesn't play well with the type system, hence the explicit type casting since the only accepted types don't include null or undefined.
Is there a way to type this userId value as nullable/nullish, and execute this query without it? Any help is greatly appreciated!1 Reply
it seems like
userId
isn't actually set to null
prior to passing in, give it some initialization to null
and see if that helps