diff --git a/test/pick.test.ts b/test/pick.test.ts index 23993e9..7a9f603 100644 --- a/test/pick.test.ts +++ b/test/pick.test.ts @@ -11,7 +11,7 @@ expectType<{ foo: number; }>(pick(['foo'])(obj)); expectType<{ foo: number; bar: string; }>(pick(['foo', 'bar'])(obj)); expectType<{ foo: number; bar: string; biz?: boolean }>(pick(['foo', 'bar', 'biz'])(obj)); // as long as some of the array has valid keys, it will accept it, but will return `never` if there are any invalid keys -expectType(pick(['baz', 'bar', 'biz'])(obj)); +expectError(pick(['baz', 'bar', 'biz'])(obj)); // if the array is only invalid keys, it will error expectError(pick(['baz'])(obj)); // make sure typed array works diff --git a/types/pick.d.ts b/types/pick.d.ts index 07de465..5d7f1c5 100644 --- a/types/pick.d.ts +++ b/types/pick.d.ts @@ -1,4 +1,4 @@ import { ElementOf } from './util/tools'; -export function pick(names: Names): , any>>>(obj: U) => string extends keyof U ? Record : ElementOf extends keyof U ? Pick> : never; -export function pick(names: Names, obj: U): string extends keyof U ? Record : Pick>; +export function pick(names: Keys): , any>>>(obj: ElementOf extends keyof U ? U : never) => ElementOf extends keyof U ? Pick> : never; +export function pick(names: readonly Keys[], obj: U): Pick;