fix: add loose auto complete to string literals where applicable #966
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Add "loose autocomplete" to
WeakPasswordReasons
,AMREntry.method
,Factor.factor_type
,SignInWithIdTokenCredentials.provider
andAuthError.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 astring
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.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 aLooseAutocomplete<T>
or something and wrap them in there but this seemed cleaner.