brackets-model
brackets-model copied to clipboard
Seeding with `CustomParticipant` not possible in TypeScript
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;
}