Closed JorensM closed 3 months ago
@JorensM, this is not a bug, this is how Typescript's UNION types work:
https://www.typescriptlang.org/docs/handbook/2/narrowing.html#the-in-operator-narrowing
if it could be either "email" or "password" - type narrowing is required
Check SignInWithPasswordCredentials
type to "see" how it is { email, ... } | { phone, ... }
@andriishupta I am aware how union types work, but I'm getting a type error even when adding a type guard. Additionally I'm not getting any autocomplete for the email and phone properties, which should be there.
@JorensM
it knows that you definitely have password
:
and after narrowing it knows that you have an email
:
in your specific example, it is not counted as "type narrowing": credentials.email == TEST_EMAIL && credentials.password == TEST_PASSWORD
if you face something else with such an example as I have provided - the issue is still open, but still unique to your case / IDE / setup
just wanted to help :) GL!
@andriishupta Thanks, I appreciate your help, I was just saying how it is for me, didn't want to sound rude or anything. I did exclude the type guard from my sample code, but in my IDE the email property wasn't showing up even after type narrowing, but it seems to be working correctly for you, so it must just be an issue on my end.
hey @JorensM, did you manage to fix your issue? it does look like an IDE specific problem here, maybe a VSCode update or restart is due 🙃
we do have the field export in the type here for a peace of mind: https://github.com/supabase/gotrue-js/blob/15c7c8258b2d42d3378be4f7738c728a07523579/src/lib/types.ts#L492
will be closing this issue but do let us know here if you've found a workaround!
@kangmingtay Hey, sorry I forgot to close this myself, yes the issue went away after updating VSCode.
Bug report
Describe the bug
I'm trying to create a mock implementation of
supabase.auth.signInWithPassword
for my tests, but for some strange reason I'm getting a type error. I'm not sure if this is a bug with TypeScript or Supabase, but from looking at the type definition ofSignInWithPasswordCredentials
, I'm not sure why the error would be shown.To Reproduce
Autocomplete also doesn't suggest me the email property
Expected behavior
Shouldn't show type error.
Screenshots
System information