Skip to content

Can't write a 'pick' function that accurately infers type arguments #12455

Closed
@DanielRosenwasser

Description

@DanielRosenwasser
declare function pick<T, K extends keyof T>(obj: T, propNames: K[]): Pick<T, K>;

let x = pick({ a: 10, b: 20, c: 30 }, ["a", "c"]);
let b = x.b;

Expected: Error on accessing x.b.
Actual: No error.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions