Drarig29 / brackets-manager.js

A simple library to manage tournament brackets (round-robin, single elimination, double elimination).
https://drarig29.github.io/brackets-docs
MIT License
245 stars 38 forks source link

Add ids to Participant example in README #162

Closed mikhail closed 1 year ago

mikhail commented 1 year ago

TypeScript checking failed when copy/pasting the README example after installing the latest version

Drarig29 commented 1 year ago

Hey @mikhail! Thanks for the PR!

However, I'm sorry I can't accept this pull request as is because it's actually the type definition for manager.update.match() that is incorrect. This function works without giving participant IDs, and I want it that way.

So I don't want to show an example with something that is not required. This example should stay minimal.

Do you still want to work on fixing the type definition in this PR? Basically, you should do a change like this (and update the rest of the code accordingly):

diff --git a/src/update.ts b/src/update.ts
index 3934e35..023e4fb 100644
--- a/src/update.ts
+++ b/src/update.ts
@@ -4,6 +4,10 @@ import { BaseUpdater } from './base/updater';
 import { ChildCountLevel } from './types';
 import * as helpers from './helpers';

+type DeepPartial<T> = T extends object ? {
+    [P in keyof T]?: DeepPartial<T[P]>;
+} : T;
+
 export class Update extends BaseUpdater {

     /**
@@ -13,7 +17,7 @@ export class Update extends BaseUpdater {
      *
      * @param match Values to change in a match.
      */
-    public async match<M extends Match = Match>(match: Partial<M>): Promise<void> {
+    public async match<M extends Match = Match>(match: DeepPartial<M>): Promise<void> {
         if (match.id === undefined)
             throw Error('No match id given.');
Drarig29 commented 1 year ago

If you don't want to work on this, it's perfectly fine! I can also close the PR and work on it. 👌

Drarig29 commented 1 year ago

It's more or less related to https://github.com/Drarig29/brackets-manager.js/issues/105. I could take this opportunity to use zod for runtime type checking.

Drarig29 commented 1 year ago

I fixed it in this commit: https://github.com/Drarig29/brackets-manager.js/commit/5b60a8d29bef68abda20da0650167a96a5c7e361

Drarig29 commented 1 year ago

Released in v1.5.8