Skip to content

Commit

Permalink
add a Tuple type helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Juhan280 committed Apr 5, 2023
1 parent a04c79c commit 831d128
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
2 changes: 2 additions & 0 deletions types/Base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { ChatInputCommandInteraction, Message } from 'discord.js';

// Helper type
export type DeepRequired<T> = T extends object ? { [K in keyof T]-?: DeepRequired<T[K]> } : T;
export type Tuple<N extends number, T> = N extends N ? (number extends N ? T[] : _TupleOf<T, N, []>) : never;
type _TupleOf<T, N extends number, R extends unknown[]> = R['length'] extends N ? R : _TupleOf<T, N, [T, ...R]>;

export type ButtonStyle = 'PRIMARY' | 'SECONDARY' | 'SUCCESS' | 'DANGER';

Expand Down
14 changes: 2 additions & 12 deletions types/TicTacToe.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -40,17 +40,7 @@ export class TicTacToe<IsSlashGame extends boolean = false> extends Approve {
options: DeepRequired<ApproveConstructorOptions & TicTacToeConstructorOptions<IsSlashGame>>;
message: MessageType<IsSlashGame>;
opponent: User;
gameBoard: [
TicTacToeGameCellState,
TicTacToeGameCellState,
TicTacToeGameCellState,
TicTacToeGameCellState,
TicTacToeGameCellState,
TicTacToeGameCellState,
TicTacToeGameCellState,
TicTacToeGameCellState,
TicTacToeGameCellState
];
gameBoard: Tuple<9, TicTacToeGameCellState>;
player1Turn: boolean;

on(
Expand Down

0 comments on commit 831d128

Please sign in to comment.