Skip to content

Commit

Permalink
[patch] handle optional properties correctly in getObjectTypedEntries…
Browse files Browse the repository at this point in the history
… and getObjectTypedValues
  • Loading branch information
electrovir committed Jul 1, 2024
1 parent 7a71171 commit be58bb9
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 62 deletions.
60 changes: 30 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "augment-vir",
"version": "29.1.5",
"version": "29.1.6",
"private": true,
"homepage": "https://github.com/electrovir/augment-vir",
"bugs": {
Expand Down
6 changes: 3 additions & 3 deletions packages/browser-testing/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/browser-testing",
"version": "29.1.5",
"version": "29.1.6",
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
"bugs": {
"url": "https://github.com/electrovir/augment-vir/issues"
Expand All @@ -23,8 +23,8 @@
"test:coverage": "npm test"
},
"dependencies": {
"@augment-vir/common": "^29.1.5",
"@augment-vir/testing": "^29.1.5",
"@augment-vir/common": "^29.1.6",
"@augment-vir/testing": "^29.1.6",
"@open-wc/testing": "^4.0.0",
"@types/mocha": "^10.0.7",
"@web/test-runner-commands": "^0.9.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/browser",
"version": "29.1.5",
"version": "29.1.6",
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/browser",
"bugs": {
"url": "https://github.com/electrovir/augment-vir/issues"
Expand All @@ -24,12 +24,12 @@
"test:watch": "web-test-runner --color --config configs/web-test-runner.config.mjs --watch"
},
"dependencies": {
"@augment-vir/common": "^29.1.5",
"@augment-vir/common": "^29.1.6",
"html-spec-tags": "^2.2.0",
"run-time-assertions": "^1.5.1"
},
"devDependencies": {
"@augment-vir/browser-testing": "^29.1.5",
"@augment-vir/browser-testing": "^29.1.6",
"@open-wc/testing": "^4.0.0",
"@types/chai": "^4.3.16",
"@types/mocha": "^10.0.7",
Expand Down
6 changes: 3 additions & 3 deletions packages/chai/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/chai",
"version": "29.1.5",
"version": "29.1.6",
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
"bugs": {
"url": "https://github.com/electrovir/augment-vir/issues"
Expand All @@ -23,8 +23,8 @@
"test:coverage": "npm test"
},
"dependencies": {
"@augment-vir/common": "^29.1.5",
"@augment-vir/testing": "^29.1.5",
"@augment-vir/common": "^29.1.6",
"@augment-vir/testing": "^29.1.6",
"type-fest": "^4.20.1"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions packages/common-tests/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/common-tests",
"version": "29.1.5",
"version": "29.1.6",
"private": true,
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common-tests",
"bugs": {
Expand All @@ -22,9 +22,9 @@
"test:types": "tsc --noEmit"
},
"devDependencies": {
"@augment-vir/chai": "^29.1.5",
"@augment-vir/common": "^29.1.5",
"@augment-vir/node-js": "^29.1.5",
"@augment-vir/chai": "^29.1.6",
"@augment-vir/common": "^29.1.6",
"@augment-vir/node-js": "^29.1.6",
"@electrovir/nyc": "^15.1.0-fix0",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@types/chai": "^4.3.16",
Expand Down
28 changes: 27 additions & 1 deletion packages/common-tests/src/tests/object/object-entries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe(getObjectTypedEntries.name, () => {
},
]);

it('has proper types', () => {
it('merges all entries into unions', () => {
const exampleObject = {
hi: 'hi',
bye: 5,
Expand All @@ -124,6 +124,20 @@ describe(getObjectTypedEntries.name, () => {
['bye' | 'hi' | 'somethingElse', string | number | RegExp][]
>();
});

it('handles optional properties', () => {
const exampleObject = {} as Partial<Record<Planet, string>>;

assertTypeOf(getObjectTypedEntries(exampleObject)).toEqualTypeOf<[Planet, string][]>();
});

it('handles nullable properties', () => {
const exampleObject = {} as Partial<Record<Planet, string | undefined>>;

assertTypeOf(getObjectTypedEntries(exampleObject)).toEqualTypeOf<
[Planet, string | undefined][]
>();
});
});

describe(getObjectTypedKeys.name, () => {
Expand Down Expand Up @@ -180,6 +194,18 @@ describe(getObjectTypedValues.name, () => {
],
},
]);

it('handles optional properties', () => {
const exampleObject = {} as Partial<Record<Planet, string>>;

assertTypeOf(getObjectTypedValues(exampleObject)).toEqualTypeOf<string[]>();
});

it('handles nullable properties', () => {
const exampleObject = {} as Partial<Record<Planet, string | undefined>>;

assertTypeOf(getObjectTypedValues(exampleObject)).toEqualTypeOf<(string | undefined)[]>();
});
});

describe(getEntriesSortedByKey.name, () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/common",
"version": "29.1.5",
"version": "29.1.6",
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
"bugs": {
"url": "https://github.com/electrovir/augment-vir/issues"
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/augments/object/object-entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ export function getObjectTypedKeys<ObjectGeneric extends unknown>(

export function getObjectTypedValues<ObjectGeneric extends unknown>(
input: ObjectGeneric,
): ObjectGeneric[keyof ObjectGeneric][] {
): Required<ObjectGeneric>[keyof ObjectGeneric][] {
return getObjectTypedKeys(input).map(
(key) => input[key],
) as ObjectGeneric[keyof ObjectGeneric][];
}

export function getObjectTypedEntries<ObjectGeneric extends unknown>(
input: ObjectGeneric,
): [keyof ObjectGeneric, ObjectGeneric[keyof ObjectGeneric]][] {
): [keyof ObjectGeneric, Required<ObjectGeneric>[keyof ObjectGeneric]][] {
return getObjectTypedKeys(input).map((key) => [
key,
input[key],
Expand Down
6 changes: 3 additions & 3 deletions packages/docker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/docker",
"version": "29.1.5",
"version": "29.1.6",
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/docker",
"bugs": {
"url": "https://github.com/electrovir/augment-vir/issues"
Expand All @@ -22,8 +22,8 @@
"test:coverage": "npm test"
},
"dependencies": {
"@augment-vir/common": "^29.1.5",
"@augment-vir/node-js": "^29.1.5"
"@augment-vir/common": "^29.1.6",
"@augment-vir/node-js": "^29.1.6"
},
"devDependencies": {
"typescript": "5.5.2"
Expand Down
6 changes: 3 additions & 3 deletions packages/node-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/node-js",
"version": "29.1.5",
"version": "29.1.6",
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/node-js",
"bugs": {
"url": "https://github.com/electrovir/augment-vir/issues"
Expand All @@ -22,7 +22,7 @@
"test:coverage": "npm test coverage"
},
"dependencies": {
"@augment-vir/common": "^29.1.5",
"@augment-vir/common": "^29.1.6",
"ansi-colors": "^4.1.3",
"axios": "^1.7.2",
"fs-extra": "^11.2.0",
Expand All @@ -31,7 +31,7 @@
"type-fest": "^4.20.1"
},
"devDependencies": {
"@augment-vir/chai": "^29.1.5",
"@augment-vir/chai": "^29.1.6",
"@electrovir/nyc": "^15.1.0-fix0",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@types/chai": "^4.3.16",
Expand Down
6 changes: 3 additions & 3 deletions packages/prisma-node-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@augment-vir/prisma-node-js",
"version": "29.1.5",
"version": "29.1.6",
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/prisma-node-js",
"bugs": {
"url": "https://github.com/electrovir/augment-vir/issues"
Expand All @@ -22,8 +22,8 @@
"test:coverage": "npm test"
},
"dependencies": {
"@augment-vir/common": "^29.1.5",
"@augment-vir/node-js": "^29.1.5",
"@augment-vir/common": "^29.1.6",
"@augment-vir/node-js": "^29.1.6",
"type-fest": "^4.20.1"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit be58bb9

Please sign in to comment.