brackets-model icon indicating copy to clipboard operation
brackets-model copied to clipboard

Seeding with `CustomParticipant` not possible in TypeScript

Open Tandashi opened this issue 1 year ago • 2 comments

When trying to create a Stage with Seeding the same way as in custom.spec.js#L16 TypeScripts errors.

This is due to the fact that a CustomParticipant also requires to have the Participant field, namingly id and tournament_id. I am not sure if this is intentional or not. Else I would propose something like this:

/**
 * The seeding for a stage.
 *
 * Each element represents a participant, which can be:
 * - A full object, with possibly extra fields.
 * - Its name.
 * - Its ID.
 * - Or a BYE: `null`.
 */
export type Seeding<Participant extends Partial<CustomParticipant> = CustomParticipant> = (Participant | string | number | null)[];

/**
 * Used to create a stage.
 */
export interface InputStage<Participant extends Partial<CustomParticipant> = Partial<CustomParticipant>> {
    /**
     * ID of the parent tournament.
     *
     * Used to determine the `number` property of a stage related to a tournament.
     */
    tournamentId: number;
    /** Name of the stage. */
    name: string;
    /** Type of stage. */
    type: StageType;
    /** The number of the stage in its tournament. Is determined if not given. */
    number?: number;
    /** Contains participants or `null` for BYEs. */
    seeding?: Seeding<Participant>;
    /** Contains optional settings specific to each stage type. */
    settings?: StageSettings;
}

Tandashi avatar Jun 26 '23 14:06 Tandashi