diff --git a/.changeset/short-cheetahs-taste.md b/.changeset/short-cheetahs-taste.md new file mode 100644 index 0000000..f3e67ba --- /dev/null +++ b/.changeset/short-cheetahs-taste.md @@ -0,0 +1,5 @@ +--- +"@first-australia/latitude-scheduler": patch +--- + +Fixed type errors diff --git a/package.json b/package.json index 836b825..1c14510 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1766690..9ef0feb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -25,6 +25,9 @@ devDependencies: '@types/luxon': specifier: ^3.3.7 version: 3.3.7 + '@types/uuid': + specifier: ^9.0.8 + version: 9.0.8 jest: specifier: ^29.7.0 version: 29.7.0(@types/node@20.10.4)(ts-node@10.9.2) @@ -1398,6 +1401,10 @@ packages: resolution: {integrity: sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==} dev: true + /@types/uuid@9.0.8: + resolution: {integrity: sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA==} + dev: true + /@types/yargs-parser@21.0.3: resolution: {integrity: sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==} dev: true diff --git a/src/presets.ts b/src/presets.ts index 2d7123d..8d4100d 100644 --- a/src/presets.ts +++ b/src/presets.ts @@ -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), }; }; diff --git a/src/v7/datetime.ts b/src/v7/datetime.ts index c7e2abe..a4cbaeb 100644 --- a/src/v7/datetime.ts +++ b/src/v7/datetime.ts @@ -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; + } } diff --git a/src/v7/instance.ts b/src/v7/instance.ts index ff47971..61b9187 100644 --- a/src/v7/instance.ts +++ b/src/v7/instance.ts @@ -17,7 +17,7 @@ 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; @@ -25,7 +25,7 @@ export default class Instance { this.loc = loc; } - static freeze(o) { + static freeze(o: Instance) { return { _class: "Instance", session_id: o.session_id, @@ -39,7 +39,7 @@ export default class Instance { }; } - static thaw(o) { + static thaw(o: ReturnType) { const I = new Instance(o.session_id, o.num, o.time, o.teams, o.loc); I.surrogates = o.surrogates; I.standins = o.standins; diff --git a/src/v7/sessions.ts b/src/v7/sessions.ts index ee53bd8..3013e8d 100644 --- a/src/v7/sessions.ts +++ b/src/v7/sessions.ts @@ -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; @@ -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) { let V: SessionType | null = null; // biome-ignore lint/complexity/noForEach: Legacy code, don't worry about it. Object.values(TYPES).forEach((v) => { @@ -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, @@ -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); } @@ -353,7 +354,7 @@ export default class SessionParams { this._usesSurrogates = value; } - static freeze(o) { + static freeze(o: SessionParams) { return { _class: "SessionParams", _id: o._id, @@ -380,7 +381,7 @@ export default class SessionParams { }; } - static thaw(o) { + static thaw(o: ReturnType) { const S = new SessionParams(o._id, o._type, o._name); S._locations = o._locations; S._universal = o._universal; @@ -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; diff --git a/src/v7/teamParams.ts b/src/v7/teamParams.ts index 21a1288..7b63ae2 100644 --- a/src/v7/teamParams.ts +++ b/src/v7/teamParams.ts @@ -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; @@ -52,7 +52,7 @@ export class TeamParams { this._number = value; } - static freeze(o) { + static freeze(o: TeamParams) { return { _class: "TeamParams", number: o.number, @@ -69,8 +69,8 @@ export class TeamParams { }; } - static thaw(o) { - const T = new TeamParams(o.id, o.number); + static thaw(o: ReturnType) { + const T = new TeamParams(o.id, Number.parseInt(o.number)); T.name = o.name; T.affiliation = o.affiliation; T.pitNum = o.pitNum; diff --git a/src/v7/tournament.ts b/src/v7/tournament.ts index 51d45cd..3ac5085 100644 --- a/src/v7/tournament.ts +++ b/src/v7/tournament.ts @@ -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"; @@ -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); } @@ -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) @@ -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(); @@ -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}`); @@ -255,32 +255,32 @@ 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, @@ -288,12 +288,12 @@ export default class EventParams { _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) { const E = new EventParams(o._version, o._title); console.log("Saved object:"); console.log(o); diff --git a/src/v8/config.ts b/src/v8/config.ts index 3e871dc..6e41f5f 100644 --- a/src/v8/config.ts +++ b/src/v8/config.ts @@ -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 */ @@ -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}`); + } } diff --git a/src/v8/initialise/ausFLL.ts b/src/v8/initialise/ausFLL.ts index 2c8454b..7277943 100644 --- a/src/v8/initialise/ausFLL.ts +++ b/src/v8/initialise/ausFLL.ts @@ -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) diff --git a/src/v8/tournament.ts b/src/v8/tournament.ts index 69798bb..f16dbfa 100644 --- a/src/v8/tournament.ts +++ b/src/v8/tournament.ts @@ -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"; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..767b015 --- /dev/null +++ b/tsconfig.json @@ -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"], +}