microsoft / microsoft/TypeScript
Record keys are inferred to be values when using `extends string` conditional in a generic type
Aperta
@weswigham ci sta già lavorando.
Dal 23/3/2023.
Bug
Domain: check: Type Inference
Rescheduled
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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>
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Valutazione
Questa issue non è ancora stata valutata.