-
-
Notifications
You must be signed in to change notification settings - Fork 6.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
getRawOne return type ought to include undefined
#7449
Comments
Simplest fix would be to change the return type to In the long-term I think it's best to enable tsconfig's |
It probably shouldn't even be |
Hi guys! Just to notice, forcing
So, in this case, and to avoid TS errors, I must use a non-null assertion for no good reason 🤷♂️ |
Documentation Issue
What was unclear or otherwise insufficient?
the typings for
getRawOne
allow any type parameterT
and blindly returns aPromise<T>
, so if you use it and no matching db row is found, it will happily lie to you and say that the row is present via the type system. this isn't wrong, per se, but it's an easy footgun.Recommended Fix
make the typing of
getRawOne
return the parameterized type| undefined
, in case there are no rows present. users of typeorm can use the non-null assertion syntax if they really think it's present.Additional Context
my company's app had unexpected 500s from this, but we're used to TypeORM making undefined access errors go away, because that's something it's particularly good at, if your typings don't do unsafe things like this.
Are you willing to resolve this issue by submitting a Pull Request?
The text was updated successfully, but these errors were encountered: