Skip to content

Commit

Permalink
New API Proposal for extending Pick/Omit and Object-Keys Helpers (#79)
Browse files Browse the repository at this point in the history
- Added RequiredKeys and OptionalKeys #53
- Added OmitByValue and PickByValue to the public API #50 
- Added OmitByValueExact and PickByValueExact #59
  • Loading branch information
piotrwitek authored Apr 28, 2019
1 parent df17c85 commit c59065a
Show file tree
Hide file tree
Showing 12 changed files with 1,102 additions and 304 deletions.
280 changes: 184 additions & 96 deletions README.md

Large diffs are not rendered by default.

437 changes: 437 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@
},
"husky": {
"hooks": {
"pre-push": "npm run ci-check"
"pre-push": "npm run pre-push"
}
},
"scripts": {
"pre-push": "npm run prettier:fix && npm run lint && npm run tsc && npm run test:update",
"ci-check": "npm run prettier && npm run lint && npm run tsc && npm run test",
"reinstall": "rm -rf node_modules/ dist/ && npm install",
"prettier": "prettier --list-different 'src/**/*.ts' || (echo '\nPlease run the following command to fix:\nnpm run prettier:fix\n'; exit 1)",
"prettier": "prettier --list-different 'src/**/*.ts' || (echo '\nPlease fix code formatting by running:\nnpm run prettier:fix\n'; exit 1)",
"prettier:fix": "prettier --write 'src/**/*.ts'",
"lint": "tslint --project './tsconfig.json'",
"tsc": "tsc -p . --noEmit",
"tsc:watch": "tsc -p . --noEmit -w",
"test": "jest --config jest.config.json --no-cache",
"test": "jest --config jest.config.json",
"test:watch": "jest --config jest.config.json --watch",
"test:update": "jest --config jest.config.json --no-cache -u && dts-jest-remap ./src/*.spec.ts --rename '{{basename}}.snap.{{extname}}'",
"prebuild": "rm -rf dist/",
"build": "tsc -p ./tsconfig.build.json --outDir dist/",
"prepublishOnly": "npm run reinstall && npm run ci-check && npm run build",
"ci-check": "npm run lint && npm run tsc && npm run test:update"
"prepublishOnly": "npm run reinstall && npm run ci-check && npm run build"
},
"dependencies": {},
"devDependencies": {
Expand Down
38 changes: 34 additions & 4 deletions src/__snapshots__/mapped-types.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ exports[`Intersection testType<Intersection<Props, DefaultProps>>() 1`] = `"Pick
exports[`NonFunctionKeys testType<NonFunctionKeys<MixedProps>>() 1`] = `"\\"name\\""`;
exports[`NonUndefined testType<NonUndefined<'1' | '2' | undefined>>() 1`] = `"\\"1\\" | \\"2\\""`;
exports[`NonUndefined testType<NonUndefined<string | null | undefined>>() 1`] = `"string | null"`;
exports[`NonUndefined testType<NonUndefined<undefined>>() 1`] = `"never"`;
Expand All @@ -110,22 +110,52 @@ exports[`Omit testType<Omit<Props, 'age'>>() 1`] = `"Omit<Props, \\"age\\">"`;
exports[`Omit testType<Omit<T, 'age'>>() 1`] = `"Omit<T, \\"age\\">"`;
exports[`OmitByValue testType<OmitByValue<Props, string | number>>() 1`] = `"Pick<Props, \\"visible\\">"`;
exports[`OmitByValue testType<OmitByValue<RequiredOptionalProps, number | undefined>>() 1`] = `"Pick<RequiredOptionalProps, \\"opt\\" | \\"optUndef\\" | undefined>"`;
exports[`OmitByValue testType<OmitByValue<T, string | number>>() 1`] = `"Pick<T, { [Key in keyof T]: T[Key] extends string | number ? never : Key; }[keyof T]>"`;
exports[`OmitByValue testType<OmitByValue<RequiredOptionalProps, number>>() 1`] = `"Pick<RequiredOptionalProps, \\"reqUndef\\" | \\"opt\\" | \\"optUndef\\" | undefined>"`;
exports[`OmitByValue testType<OmitByValue<RequiredOptionalProps, undefined>>() 1`] = `"Pick<RequiredOptionalProps, \\"req\\" | \\"reqUndef\\" | \\"opt\\" | \\"optUndef\\" | undefined>"`;
exports[`OmitByValue testType<OmitByValue<T, string | boolean>>() 1`] = `"Pick<T, { [Key in keyof T]: T[Key] extends string | boolean ? never : Key; }[keyof T]>"`;
exports[`OmitByValueExact testType<OmitByValueExact<RequiredOptionalProps, number | undefined>>() 1`] = `"Pick<RequiredOptionalProps, \\"req\\" | \\"opt\\" | \\"optUndef\\" | undefined>"`;
exports[`OmitByValueExact testType<OmitByValueExact<RequiredOptionalProps, number>>() 1`] = `"Pick<RequiredOptionalProps, \\"reqUndef\\" | \\"opt\\" | \\"optUndef\\" | undefined>"`;
exports[`OmitByValueExact testType<OmitByValueExact<RequiredOptionalProps, undefined>>() 1`] = `"Pick<RequiredOptionalProps, \\"req\\" | \\"reqUndef\\" | \\"opt\\" | \\"optUndef\\" | undefined>"`;
exports[`OmitByValueExact testType<OmitByValueExact<T, number>>() 1`] = `"Pick<T, { [Key in keyof T]: [number] extends [T[Key]] ? [T[Key]] extends [T[Key] & number] ? never : Key : Key; }[keyof T]>"`;
exports[`OptionalKeys testType<OptionalKeys<RequiredOptionalProps>>() 1`] = `"\\"opt\\" | \\"optUndef\\""`;
exports[`Overwrite const result: Overwrite<Omit<T, 'age'>, T> = rest 1`] = `"any"`;
exports[`Overwrite testType<Overwrite<Props, NewProps>>() 1`] = `"Pick<Pick<Props, \\"name\\" | \\"visible\\"> & Pick<NewProps, \\"age\\">, \\"name\\" | \\"age\\" | \\"visible\\">"`;
exports[`PickByValue testType<PickByValue<Props, string | number>>() 1`] = `"Pick<Props, \\"name\\" | \\"age\\">"`;
exports[`PickByValue testType<PickByValue<RequiredOptionalProps, number | undefined>>() 1`] = `"Pick<RequiredOptionalProps, \\"req\\" | \\"reqUndef\\" | undefined>"`;
exports[`PickByValue testType<PickByValue<RequiredOptionalProps, number>>() 1`] = `"Pick<RequiredOptionalProps, \\"req\\" | undefined>"`;
exports[`PickByValue testType<PickByValue<RequiredOptionalProps, undefined>>() 1`] = `"Pick<RequiredOptionalProps, undefined>"`;
exports[`PickByValue testType<PickByValue<T, number>>() 1`] = `"Pick<T, { [Key in keyof T]: T[Key] extends number ? Key : never; }[keyof T]>"`;
exports[`PickByValueExact testType<PickByValueExact<RequiredOptionalProps, number | undefined>>() 1`] = `"Pick<RequiredOptionalProps, \\"reqUndef\\" | undefined>"`;
exports[`PickByValueExact testType<PickByValueExact<RequiredOptionalProps, number>>() 1`] = `"Pick<RequiredOptionalProps, \\"req\\" | undefined>"`;
exports[`PickByValueExact testType<PickByValueExact<RequiredOptionalProps, undefined>>() 1`] = `"Pick<RequiredOptionalProps, undefined>"`;
exports[`PickByValueExact testType<PickByValueExact<T, number>>() 1`] = `"Pick<T, { [Key in keyof T]: [number] extends [T[Key]] ? [T[Key]] extends [T[Key] & number] ? Key : never : never; }[keyof T]>"`;
exports[`Primitive testType<Primitive>() 1`] = `"Primitive"`;
exports[`PromiseType testType<PromiseType<Promise<string>>>() 1`] = `"string"`;
exports[`ReadonlyKeys testType<ReadonlyKeys<ReadWriteProps>>() 1`] = `"\\"a\\""`;
exports[`RequiredKeys testType<RequiredKeys<RequiredOptionalProps>>() 1`] = `"\\"req\\" | \\"reqUndef\\""`;
exports[`SetComplement testType<SetComplement<'1' | '2' | '3', '2' | '3'>>() 1`] = `"\\"1\\""`;
exports[`SetDifference testType<SetDifference<'1' | '2' | '3', '2' | '3' | '4'>>() 1`] = `"\\"1\\""`;
Expand Down
2 changes: 1 addition & 1 deletion src/__snapshots__/utility-types.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ exports[`$ElementType testType<$ElementType<boolean[], number>>() 1`] = `"boolea
exports[`$Keys testType<$Keys<Props>>() 1`] = `"\\"name\\" | \\"age\\" | \\"visible\\""`;
exports[`$NonMaybeType testType<$NonMaybeType<string|null|undefined>>() 1`] = `"string"`;
exports[`$NonMaybeType testType<$NonMaybeType<string | null | undefined>>() 1`] = `"string"`;
exports[`$PropertyType testType<$PropertyType<[boolean, number], '0'>>() 1`] = `"boolean"`;
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ export {
NonFunctionKeys,
NonUndefined,
Omit,
OmitByValue,
OmitByValueExact,
OptionalKeys,
Overwrite,
PickByValue,
PickByValueExact,
Primitive,
PromiseType,
ReadonlyKeys,
RequiredKeys,
SetComplement,
SetDifference,
SetIntersection,
Expand Down
Loading

0 comments on commit c59065a

Please sign in to comment.