Skip to content

Commit 6789308

Browse files
authored
fix: adjust "valuesOf" types (#67)
1 parent 7b2ea8a commit 6789308

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kasnix/structured-objects",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"repository": {
55
"type": "git",
66
"url": "git+https://github.com/luckasnix/structured-objects.git"

src/object-graph.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,18 @@ export class ObjectGraph<NodeValue extends Record<string, unknown>> {
162162
* @description Returns all values of the provided property.
163163
* @since 1.0.0
164164
*/
165-
public valuesOf(propertyKey: keyof NodeValue): Array<NodeValue[keyof NodeValue]> {
166-
if (!propertyKey) {
167-
throw new Error("Provide a value for the 'propertyKey' parameter");
165+
public valuesOf<NodeValueKey extends keyof NodeValue>(
166+
nodeValueKey: NodeValueKey,
167+
): Array<NodeValue[NodeValueKey]> {
168+
if (!nodeValueKey) {
169+
throw new Error("Provide a value for the 'nodeValueKey' parameter");
168170
}
169-
if (typeof propertyKey !== "string") {
170-
throw new TypeError("The parameter 'propertyKey' must be a string");
171+
if (typeof nodeValueKey !== "string") {
172+
throw new TypeError("The parameter 'nodeValueKey' must be a string");
171173
}
172-
const propertyValues: Set<NodeValue[keyof NodeValue]> = new Set();
174+
const propertyValues: Set<NodeValue[NodeValueKey]> = new Set();
173175
for (const [_, nodeValue] of this.nodes) {
174-
propertyValues.add(nodeValue[propertyKey as keyof NodeValue]);
176+
propertyValues.add(nodeValue[nodeValueKey as NodeValueKey]);
175177
}
176178
return Array.from(propertyValues);
177179
}

0 commit comments

Comments
 (0)