Skip to content

Commit

Permalink
Remove generics from transform function
Browse files Browse the repository at this point in the history
  • Loading branch information
ogzhanolguncu committed Oct 19, 2023
1 parent 28fc701 commit 0235c4c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
19 changes: 4 additions & 15 deletions pkg/commands/geo_pos.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
assertEquals,
assertStrictEquals,
} from "https://deno.land/[email protected]/testing/asserts.ts";
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { newHttpClient } from "../test-utils.ts";
import { GeoAddCommand } from "./geo_add.ts";
import { GeoPosCommand } from "./geo_pos.ts";
Expand All @@ -17,9 +14,7 @@ Deno.test("should swallow non-existing member and return only the valid ones", a
{ longitude: 15.087269, latitude: 37.502669, member: members[1] },
{ longitude: 12.4372, latitude: 37.7981, member: members[2] },
]).exec(client);
const response = await new GeoPosCommand([key, [...members, "FooBar"]]).exec(
client,
);
const response = await new GeoPosCommand([key, [...members, "FooBar"]]).exec(client);
assertEquals(response.length, 3);
});

Expand Down Expand Up @@ -51,19 +46,13 @@ Deno.test("should return empty array due to null value FooBar", async () => {

Deno.test("should work with object members", async () => {
const key = "Sicily";
const members = [
{ name: "Palermo" },
{ name: "Catania" },
{ name: "Marsala" },
];
const members = [{ name: "Palermo" }, { name: "Catania" }, { name: "Marsala" }];
await new GeoAddCommand([
key,
{ longitude: 13.361389, latitude: 38.115556, member: members[0] },
{ longitude: 15.087269, latitude: 37.502669, member: members[1] },
{ longitude: 12.4372, latitude: 37.7981, member: members[2] },
]).exec(client);
const response = await new GeoPosCommand([key, [...members, "FooBar"]]).exec(
client,
);
const response = await new GeoPosCommand([key, [...members, "FooBar"]]).exec(client);
assertEquals(response.length, 3);
});
15 changes: 5 additions & 10 deletions pkg/commands/geo_pos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ type Coordinates = {
/**
* @see https://redis.io/commands/geopos
*/
export class GeoPosCommand<TMember = string> extends Command<
(string | null)[][],
Coordinates[]
> {
export class GeoPosCommand<TMember = string> extends Command<(string | null)[][], Coordinates[]> {
constructor(
cmd: [string, ...TMember[] | TMember[]],
opts?: CommandOptions<(string | null)[][], Coordinates[]>,
cmd: [string, ...(TMember[] | TMember[])],
opts?: CommandOptions<(string | null)[][], Coordinates[]>
) {
const [key] = cmd;
// Check if the second argument is an array of strings (members).
Expand All @@ -29,13 +26,11 @@ export class GeoPosCommand<TMember = string> extends Command<
}
}

function transform<TData extends Coordinates[]>(
result: (string | null)[][],
): TData {
function transform(result: (string | null)[][]): Coordinates[] {
const final: Coordinates[] = [];
for (const pos of result) {
if (!pos?.[0] || !pos?.[1]) continue;
final.push({ lng: pos[0], lat: pos[1] });
}
return final as TData;
return final;
}

0 comments on commit 0235c4c

Please sign in to comment.