This repository was archived by the owner on Oct 10, 2025. It is now read-only.
Commit fd9248d
authored
fix: add loose auto complete to string literals where applicable (#966)
## What kind of change does this PR introduce?
Add "loose autocomplete" to`WeakPasswordReasons`, `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.
<img width="632" alt="image"
src="https://github.com/user-attachments/assets/a6bd07c1-c460-4b80-87ae-2c855e996157">
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.1 parent 67d3e86 commit fd9248d
2 files changed
+5
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
| 97 | + | |
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| |||
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
274 | | - | |
| 274 | + | |
275 | 275 | | |
276 | 276 | | |
277 | 277 | | |
| |||
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
313 | | - | |
| 313 | + | |
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
| |||
604 | 604 | | |
605 | 605 | | |
606 | 606 | | |
607 | | - | |
| 607 | + | |
608 | 608 | | |
609 | 609 | | |
610 | 610 | | |
| |||
0 commit comments