Skip to content
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

fix: add loose auto complete to string literals where applicable #966

Merged
merged 1 commit into from
Nov 14, 2024

Conversation

janglad
Copy link
Contributor

@janglad janglad commented Sep 28, 2024

What kind of change does this PR introduce?

Add "loose autocomplete" toWeakPasswordReasons, AMREntry.method, Factor.factor_type, SignInWithIdTokenCredentials.provider and AuthError.code

What is the current behavior?

The above types define possible string literal values, which is great, but they're unioned with string. As a regular "literal" | string just ends up as a string this foregoes the benefit of defining the literals in the first place.

What is the new behavior?

TypeScript still allows any possible string as a valid value (notice no error on the "not in there"), but now the predefined literals show up as hints. This is done by using "literal" | string & {}. While this seems hacky, it's something that works and something the TS team test against meaning they won't "fix" it in future releases.

image

Currently these hints aren't shown as the type just ends up as a simple string.

Additional context

I believe this can be quite helpful for people when trying to handle errors etc. I know string & {} might look somewhat weird for maintainers, if preferable I can create a LooseAutocomplete<T> or something and wrap them in there but this seemed cleaner.

@janglad janglad changed the title add "loose auto complete" where applicable Add "loose auto complete" to string literals where applicable Sep 28, 2024
@janglad
Copy link
Contributor Author

janglad commented Nov 12, 2024

@J0 just checking in if you could have a look at this 🙏. Maybe this change is unwanted but either way it should be a relatively quick review and it would make my life a tiny bit nicer 😄

@J0 J0 changed the title Add "loose auto complete" to string literals where applicable fix: add loose auto complete to string literals where applicable Nov 13, 2024
@J0
Copy link
Contributor

J0 commented Nov 13, 2024

@janglad Thanks for the PR - could we trouble you to point us to the relevant TypeScript docs for this (if any)?

@janglad
Copy link
Contributor Author

janglad commented Nov 13, 2024

@janglad Thanks for the PR - could we trouble you to point us to the relevant TypeScript docs for this (if any)?

I'm sadly not aware of any official documentation for this. It it is however something that's used in quite a few big libraries (like the types for React). FWIW TS tests agains Definitely Typed and very rarely does breaking changes, I would personally not worry that this breaks in the future.

@J0 J0 merged commit fd9248d into supabase:master Nov 14, 2024
1 of 4 checks passed
@J0
Copy link
Contributor

J0 commented Nov 14, 2024

Thank you!

@janglad
Copy link
Contributor Author

janglad commented Nov 14, 2024

Yay, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants