microsoft / microsoft/TypeScript
KnownKeys<T> breaking change in 4.3.1-rc
Abierto
@weswigham ya está trabajando en esto.
Desde el 18/5/2021.
Bug
Domain: Conditional Types
Rescheduled
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
Bug Report
🔎 Search Terms
KnownKeys, never, getting known interface keys
🕗 Version & Regression Information
- This changed between versions 4.3.0-beta and 4.3.1-rc
⏯ Playground Link
- 4.3.0-beta playground – types work.
- 4.4.0 playground – types fail. This issue also exists in 4.3.1-rc but that version isn't in the playground.
💻 Code
type KnownKeys<T> = {
[K in keyof T]: string extends K ? never : number extends K ? never : K
} extends { [_ in keyof T]: infer U } ? U : never;
interface HasStringKeys {
[s: string]: any;
}
interface ThingWithKeys extends HasStringKeys {
foo: unknown;
bar: unknown;
}
const demo: KnownKeys<ThingWithKeys> = 'foo';
🙁 Actual behavior
demo has type never.
🙂 Expected behavior
demo has type 'foo' | 'bar'.
Other info
I'm not sure where I got KnownKeys from, but it appears on https://stackoverflow.com/a/51956054/123395.
This issue impacted https://www.npmjs.com/package/idb, but I've already worked around the issue by using the other method on that StackOverflow post. https://github.com/jakearchibald/idb/commit/e3c76a59f6ab461b03ceabebc24dea826a074a76
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Evaluación
Este issue todavía no se ha evaluado.