microsoft / microsoft/TypeScript

`Extract` not narrowing type union in mapped type passed as generic

Aperta
#57,827 6 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@weswigham ci sta già lavorando.

Dal 18/3/2024.

Needs Investigation
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

🔎 Search Terms

Extract, type union

🕗 Version & Regression Information
  • This changed between versions 5.33 and 5.4
⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.4.2#code/C4TwDgpgBAysBOBLAdgcwNIRAZwDwBUA+KAXigFEAPBAQwGNhcBrLAewDMoBvAWACgogqAG0AClBRQWIDlHxQa2OWIC6UCNQjIAJkuwIUqKAH4oogFxRkEAG4R4KyzWQh+AXwA0UfUjSF+-HSsyPpQAEYANqysYKRQBB6EABQAXpZwvhhYeEQAlKTEvAJQQSHAUOyWPoZxKe4BfCjA9uz00Ira3PyCAI4A7hBVBmj1fPwREOU06cNZOLgd-nxAA

💻 Code
type StringKeys<T> = Extract<keyof {
    [P in keyof T as T[P] extends string ? P: never]: any
}, string>

const bloop = <T,>(z: StringKeys<T>) => {
  const f: string = z
}

interface asd {
  qwe: string
}

let a: StringKeys<asd>

🙁 Actual behavior

z is not assignable to string in the bloop function

🙂 Expected behavior

z should be assignable to string, because we extract string-extending keys

Additional information about the issue

This was working just fine on 5.3.3, and continues to work when the generic is concretized (hence the let at the bottom of the example)

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.