From 831d12828401bc3fb0089bcbbb2cd5059c733b90 Mon Sep 17 00:00:00 2001 From: Juhan280 <92646057+Juhan280@users.noreply.github.com> Date: Wed, 5 Apr 2023 13:52:05 +0600 Subject: [PATCH] add a Tuple type helper --- types/Base.d.ts | 2 ++ types/TicTacToe.d.ts | 14 ++------------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/types/Base.d.ts b/types/Base.d.ts index 542b3a6..1a5e250 100644 --- a/types/Base.d.ts +++ b/types/Base.d.ts @@ -2,6 +2,8 @@ import { ChatInputCommandInteraction, Message } from 'discord.js'; // Helper type export type DeepRequired = T extends object ? { [K in keyof T]-?: DeepRequired } : T; +export type Tuple = N extends N ? (number extends N ? T[] : _TupleOf) : never; +type _TupleOf = R['length'] extends N ? R : _TupleOf; export type ButtonStyle = 'PRIMARY' | 'SECONDARY' | 'SUCCESS' | 'DANGER'; diff --git a/types/TicTacToe.d.ts b/types/TicTacToe.d.ts index d645d51..4124a38 100644 --- a/types/TicTacToe.d.ts +++ b/types/TicTacToe.d.ts @@ -8,7 +8,7 @@ import { User, } from 'discord.js'; import { Approve, ApproveConstructorOptions } from './Approve'; -import { BaseConstructorOptions, ButtonStyle, DeepRequired, MessageType } from './Base'; +import { BaseConstructorOptions, ButtonStyle, DeepRequired, MessageType, Tuple } from './Base'; export type TicTacToeGameCellState = 0 | 1 | 2; @@ -40,17 +40,7 @@ export class TicTacToe extends Approve { options: DeepRequired>; message: MessageType; opponent: User; - gameBoard: [ - TicTacToeGameCellState, - TicTacToeGameCellState, - TicTacToeGameCellState, - TicTacToeGameCellState, - TicTacToeGameCellState, - TicTacToeGameCellState, - TicTacToeGameCellState, - TicTacToeGameCellState, - TicTacToeGameCellState - ]; + gameBoard: Tuple<9, TicTacToeGameCellState>; player1Turn: boolean; on(