microsoft / microsoft/TypeScript
Record keys are inferred to be values when using `extends string` conditional in a generic type
Abierto
@weswigham ya está trabajando en esto.
Desde el 23/3/2023.
Bug
Domain: check: Type Inference
Rescheduled
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
Bug Report
🔎 Search Terms
inference generic extends record
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about "extends"
⏯ Playground Link
Playground link with relevant code
💻 Code
type TestType<Keys extends string> = string extends Keys ? Record<Keys, string> : Record<Keys, string>
function inferHelper<Keys extends string>(data: TestType<Keys>) {
return data;
}
export const a = inferHelper({
// key1 is inferred to be value1 here
key1: "value1"
})
🙁 Actual behavior
ts2345
Argument of type '{ key1: string; }' is not assignable to parameter of type 'Record<"value1", string>'.
Object literal may only specify known properties, and 'key1' does not exist in type 'Record<"value1", string>'
🙂 Expected behavior
no error, and the record is inferred as Record<"key1", string>
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.