Skip to content

Commit

Permalink
✅ test: fix type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
fwestling committed Mar 21, 2024
1 parent 14a37f6 commit 469b722
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 46 deletions.
5 changes: 5 additions & 0 deletions .changeset/short-cheetahs-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@first-australia/latitude-scheduler": patch
---

Fixed type errors
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@changesets/cli": "^2.27.1",
"@types/jest": "^29.5.11",
"@types/luxon": "^3.3.7",
"@types/uuid": "^9.0.8",
"jest": "^29.7.0",
"lefthook": "^1.6.7",
"ts-jest": "^29.1.1",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const getPreset = (preset: Preset): PresetReturn => {
const getPresetAUSFLL = (): PresetReturn => {
return {
activities: [],
config: new TournamentConfig(),
options: new TournamentOptions(),
config: new TournamentConfig(9*60, 15*60, 1),
options: new TournamentOptions(1),
};
};
5 changes: 5 additions & 0 deletions src/v7/datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ export class TimeSlot {
start: TimePoint;
/** Duration of this timeslot, in minutes */
duration: number;

constructor(start: TimePoint, duration: number) {
this.start = start;
this.duration = duration;
}
}
6 changes: 3 additions & 3 deletions src/v7/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ export default class Instance {
standins = 0;
extra = false;

constructor(session_id, num, time, teams, loc) {
constructor(session_id: string, num: number, time: TimePoint, teams: string[], loc: number) {
this.session_id = session_id;
this.num = num;
this.time = time;
this.teams = teams;
this.loc = loc;
}

static freeze(o) {
static freeze(o: Instance) {
return {
_class: "Instance",
session_id: o.session_id,
Expand All @@ -39,7 +39,7 @@ export default class Instance {
};
}

static thaw(o) {
static thaw(o: ReturnType<typeof Instance.freeze>) {
const I = new Instance(o.session_id, o.num, o.time, o.teams, o.loc);
I.surrogates = o.surrogates;
I.standins = o.standins;
Expand Down
31 changes: 16 additions & 15 deletions src/v7/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ export class SessionType {
_defaultLocations: string;
_fillerPolicy: FillerPolicy;
constructor(
uid,
name,
priority,
defaultTitle,
defaultLocations,
uid: number,
name: string,
priority: number,
defaultTitle: string,
defaultLocations: string,
fillerPolicy: FillerPolicy = "blank"
) {
console.log("uid", uid);
this._name = name;
this._priority = priority;
this._defaultTitle = defaultTitle;
Expand Down Expand Up @@ -47,14 +48,14 @@ export class SessionType {
return this._defaultLocations;
}

static freeze(o) {
static freeze(o: SessionType) {
return {
_class: "SessionType",
_name: o.name,
};
}

static thaw(o) {
static thaw(o: ReturnType<typeof SessionType.freeze>) {
let V: SessionType | null = null;
// biome-ignore lint/complexity/noForEach: Legacy code, don't worry about it.
Object.values(TYPES).forEach((v) => {
Expand Down Expand Up @@ -140,9 +141,9 @@ export default class SessionParams {
private _usesSurrogates = false;

constructor(
uid,
type,
name,
uid: string,
type: SessionType,
name: string,
nLocs = 4,
startTime?: TimePoint,
endTime?: TimePoint,
Expand Down Expand Up @@ -340,7 +341,7 @@ export default class SessionParams {
}

// Does this session apply to id?
applies(id) {
applies(id: string) {
if (this.universal) return true;
return this.appliesTo.includes(id);
}
Expand All @@ -353,7 +354,7 @@ export default class SessionParams {
this._usesSurrogates = value;
}

static freeze(o) {
static freeze(o: SessionParams) {
return {
_class: "SessionParams",
_id: o._id,
Expand All @@ -380,7 +381,7 @@ export default class SessionParams {
};
}

static thaw(o) {
static thaw(o: ReturnType<typeof SessionParams.freeze>) {
const S = new SessionParams(o._id, o._type, o._name);
S._locations = o._locations;
S._universal = o._universal;
Expand All @@ -389,11 +390,11 @@ export default class SessionParams {
if (
S._endTime?.time === undefined &&
S._startTime &&
o._actualEndTime.mins === null
o._actualEndTime?.time === null
)
S._endTime = S._startTime.clone(30);
else if (S._endTime?.time === undefined) {
S._endTime = o._actualEndTime.clone();
S._endTime = o._actualEndTime?.clone();
}
S._actualStartTime = o._actualStartTime;
S._actualEndTime = o._actualEndTime;
Expand Down
12 changes: 6 additions & 6 deletions src/v7/teamParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export class TeamParams {

schedule: Instance[] = [];

constructor(id, number) {
this.number = number;
this.name = `Team ${number}`;
constructor(id: string, number: number) {
this._number = `${number}`;
this._name = `Team ${number}`;

// this.id = new ShortUniqueId();
this._id = id;
Expand Down Expand Up @@ -52,7 +52,7 @@ export class TeamParams {
this._number = value;
}

static freeze(o) {
static freeze(o: TeamParams) {
return {
_class: "TeamParams",
number: o.number,
Expand All @@ -69,8 +69,8 @@ export class TeamParams {
};
}

static thaw(o) {
const T = new TeamParams(o.id, o.number);
static thaw(o: ReturnType<typeof TeamParams.freeze>) {
const T = new TeamParams(o.id, Number.parseInt(o.number));
T.name = o.name;
T.affiliation = o.affiliation;
T.pitNum = o.pitNum;
Expand Down
34 changes: 17 additions & 17 deletions src/v7/tournament.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type AwardPreset, awardPresetToList, awardPresets } from "../awards";
import { TimePoint, type TournamentDateConfig } from "./datetime";
import { TournamentSponsors } from "./sponsors";
import { TimePoint, TournamentDateConfig } from "./datetime";
import { type Sponsor, TournamentSponsors } from "./sponsors";
import { TeamParams } from "./teamParams";
import type { Version } from "../types/version";

Expand Down Expand Up @@ -38,19 +38,19 @@ export default class EventParams {
_errors: number;

constructor(
version,
version: Version,
title = "Tournament",
nTeams = 24,
startTime = new TimePoint(0, 9 * 60),
endTime = new TimePoint(0, 9 * 17)
) {
this._version = version;
this.title = title;
this._title = title;
let id = Math.floor(Math.random() * 100 + 1);
const A: TeamParams[] = [];
let n = nTeams;
while (n > 0) {
A.push(new TeamParams(id, n));
A.push(new TeamParams(`${id}`, n));
n--;
id += Math.floor(Math.random() * 100 + 1);
}
Expand All @@ -61,8 +61,8 @@ export default class EventParams {
return Number.parseInt(a.number, 10) - Number.parseInt(b.number, 10);
});

this.startTime = startTime;
this.endTime = endTime;
this._startTime = startTime;
this._endTime = endTime;

// PreComputedImages.nationalSponsors.forEach((x) =>
// this.addNationalSponsor(x)
Expand All @@ -72,6 +72,7 @@ export default class EventParams {
this._tempNames = undefined;
this._pageFormat = undefined;

this._days = new TournamentDateConfig();
// console.log(this.logoBotRight);
this._errors = Number.POSITIVE_INFINITY;
// this.populateFLL();
Expand Down Expand Up @@ -166,7 +167,6 @@ export default class EventParams {
}

get awardPerc() {
const idx = this.awardStyleIdx;
console.log(`Award style index: ${this.awardStyleIdx}`);
console.log(`Award style: ${this._awardStyle}`);

Expand Down Expand Up @@ -255,45 +255,45 @@ export default class EventParams {
// });
}

addLocalSponsor(value) {
addLocalSponsor(value: Sponsor) {
this._sponsors.addLocalSponsor(value);
}

addNationalSponsor(value) {
addNationalSponsor(value: Sponsor) {
this._sponsors.addNationalSponsor(value);
}

deleteLocalSponsor(idx) {
deleteLocalSponsor(idx: number) {
this._sponsors.deleteLocalSponsor(idx);
}

static freeze(o) {
static freeze(o: EventParams) {
return {
_class: "EventParams",
_version: o._version,
_title: o._title,
_teams: o._teams,
uid_counter: o.uid_counter,
uid_counter: o._uid_counter,
_startTime: o._startTime,
_endTime: o._endTime,
_sessions: o._sessions,
_days: o._days,
_pilot: o._pilot,
_nTables: o._nTables,
errors: o.errors,
errors: o._errors,
_extraTime: o._extraTime,
_minTravel: o._minTravel,
_judgesAwards: o._judgesAwards,
_awards: o._awards,
_consolidatedAwards: o._consolidatedAwards,
_awardStyle: o._awardStyle,
_volunteers: o._volunteers,
pageFormat: o.pageFormat,
sponsors: o.sponsors.local,
pageFormat: o._pageFormat,
sponsors: o._sponsors,
};
}

static thaw(o) {
static thaw(o: ReturnType<typeof EventParams.freeze>) {
const E = new EventParams(o._version, o._title);
console.log("Saved object:");
console.log(o);
Expand Down
10 changes: 10 additions & 0 deletions src/v8/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export class TournamentConfig {
endTime: number;
/** For how many days does this tournament run? */
numberOfDays: number;

constructor(startTime: number, endTime: number, numberOfDays: number) {
this.startTime = startTime;
this.endTime = endTime;
this.numberOfDays = numberOfDays;
}
}

/** Aesthetic options for tournament export */
Expand All @@ -25,4 +31,8 @@ export class TournamentOptions {
*/
dayNames: string[];
awardPreset: AwardPreset = "reqopt0f";

constructor(numberOfDays: number) {
this.dayNames = new Array(numberOfDays).fill("").map((_, i) => `Day ${i + 1}`);
}
}
2 changes: 1 addition & 1 deletion src/v8/initialise/ausFLL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type Tournament from "../tournament";
const initAusFLL = (tournament: Tournament) => {
let time = tournament.config.startTime;
const numTeams = tournament.teams.length;
const numTables = 4;
// const numTables = 4;

tournament.activities.push(
new Activity("Opening Ceremony", "all", time, 30, 0)
Expand Down
3 changes: 1 addition & 2 deletions src/v8/tournament.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AwardPreset } from "../awards";
import { type Preset, getPreset } from "../presets";
import { getPreset, type Preset } from "../presets";
import type Activity from "./activity";
import type { TournamentConfig, TournamentOptions } from "./config";
import Team from "./team";
Expand Down
33 changes: 33 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,

/* absolute import */
"baseUrl": "./src",
"paths": {
"@/*": ["./*"],
},

/* Suppresses ts-jest error */
"esModuleInterop": true,

},
"include": ["src", "./jest.config.ts"],
}

0 comments on commit 469b722

Please sign in to comment.