microsoft / microsoft/TypeScript

KnownKeys<T> breaking change in 4.3.1-rc

Aperta
#44,143 9 commenti 8 reazioni 1 assegnatario Vedi su GitHub

@weswigham ci sta già lavorando.

Dal 18/5/2021.

Bug Domain: Conditional Types Rescheduled
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

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
💻 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

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.