From 5b64ae8f070222ef2549469649a2b5ec7ef3441a Mon Sep 17 00:00:00 2001 From: xShadowBlade Date: Tue, 11 Jun 2024 17:08:15 +0700 Subject: [PATCH] Change grid template type --- dist/types/classes/Grid.d.ts | 6 +++--- src/classes/Grid.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dist/types/classes/Grid.d.ts b/dist/types/classes/Grid.d.ts index e68f4ff..47ebfc1 100644 --- a/dist/types/classes/Grid.d.ts +++ b/dist/types/classes/Grid.d.ts @@ -6,7 +6,7 @@ import type { UnknownObject } from "../common/types"; * Represents a grid cell with coordinates and properties. * @template P - The type of the properties of the grid cell. */ -declare class GridCell

{ +declare class GridCell

{ /** The x-coordinate of the cell. */ x: number; /** The y-coordinate of the cell. */ @@ -32,13 +32,13 @@ declare class GridCell

{ * @param name - The name of the property. * @returns - The value of the property. */ - getValue(name: string): unknown; + getValue(name: keyof P): P[keyof P]; } /** * Represents a grid with cells. * @template P - The type of the properties of the grid cells. */ -declare class Grid

{ +declare class Grid

{ /** The size of the grid along the x-axis. */ xSize: number; /** The size of the grid along the x-axis. */ diff --git a/src/classes/Grid.ts b/src/classes/Grid.ts index 5104781..902364c 100644 --- a/src/classes/Grid.ts +++ b/src/classes/Grid.ts @@ -7,7 +7,7 @@ import type { UnknownObject } from "../common/types"; * Represents a grid cell with coordinates and properties. * @template P - The type of the properties of the grid cell. */ -class GridCell

{ +class GridCell

{ /** The x-coordinate of the cell. */ public x: number; @@ -45,7 +45,7 @@ class GridCell

{ * @param name - The name of the property. * @returns - The value of the property. */ - public getValue (name: string): unknown { + public getValue (name: keyof P): P[keyof P] { return this.properties[name]; } } @@ -54,7 +54,7 @@ class GridCell

{ * Represents a grid with cells. * @template P - The type of the properties of the grid cells. */ -class Grid

{ +class Grid

{ /** The size of the grid along the x-axis. */ public xSize: number;