-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Conditional TypesThe issue relates to conditional typesThe issue relates to conditional typesFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
Milestone
Description
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. jakearchibald/idb@e3c76a5
davissorenson, fregante, midskyey, felschr, falkenhawk and 2 morefalkenhawk
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Conditional TypesThe issue relates to conditional typesThe issue relates to conditional typesFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone