feat: enable TS strict mode (#168)

* feat: enable TS strict mode

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: colors bug with default

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: text type errors

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors - add definite assignment assertion

* fix: strict TS errors - add definite assignment assertion

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix(ESLint): error on no-explicit-any

* fix: type annotations for any types

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors (and remove packages)

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* fix: strict TS errors

* feat: enable React.StrictMode

* fix: strict TS errors (done!)

* fix: build error

* fix: replace no-explicit-any assertions

* refactor: cleanup

* refactor: more cleanup

* style: prettier

---------

Co-authored-by: Lukas Zenick <lukas@utexas.edu>
Co-authored-by: Razboy20 <razboy20@gmail.com>
This commit is contained in:
doprz
2024-03-21 13:19:40 -05:00
committed by GitHub
parent 0c76052478
commit efed1c0edb
61 changed files with 562 additions and 1309 deletions

View File

@@ -43,40 +43,40 @@ export type Semester = {
*/
export class Course {
/** Every course has a uniqueId within UT's registrar system corresponding to each course section */
uniqueId: number;
uniqueId!: number;
/** This is the course number for a course, i.e CS 314 would be 314, MAL 306H would be 306H */
number: string;
number!: string;
/** The full name of the course, i.e. CS 314 Data Structures and Algorithms */
fullName: string;
fullName!: string;
/** Just the english name for a course, without the number and department */
courseName: string;
courseName!: string;
/** The unique identifier for which department that a course belongs to, i.e. CS, MAL, etc. */
department: string;
department!: string;
/** The number of credits that a course is worth */
creditHours: number;
creditHours!: number;
/** Is the course open, closed, waitlisted, or cancelled? */
status: StatusType;
status!: StatusType;
/** all the people that are teaching this course, and some metadata about their names */
instructors: Instructor[];
/** Some courses at UT are reserved for certain groups of people or people within a certain major, which makes it difficult for people outside of that group to register for the course. */
isReserved: boolean;
isReserved!: boolean;
/** The description of the course as an array of "lines". This will include important information as well as a short summary of the topics covered */
description?: string[];
/** The schedule for the course, which includes the days of the week that the course is taught, the time that the course is taught, and the location that the course is taught */
schedule: CourseSchedule;
/** the link to the course details page for this course */
url: string;
url!: string;
/** the link to the registration page for this course, for easy access when registering */
registerURL?: string;
/** At UT, some courses have certain "flags" which aid in graduation */
flags: string[];
flags!: string[];
/** How is the class being taught (online, hybrid, in person, etc) */
instructionMode: InstructionMode;
instructionMode!: InstructionMode;
/** Which semester is the course from */
semester: Semester;
semester!: Semester;
/** Unix timestamp of when the course was last scraped */
scrapedAt: number;
scrapedAt!: number;
/** The colors of the course when displayed */
colors: CourseColors;

View File

@@ -30,15 +30,15 @@ export type Location = {
*/
export class CourseMeeting {
/** The day of the week that the course is taught */
days: Day[];
days!: Day[];
/** NOTE: Times starting and after 12 PM have an additional 720 minutes (12 hrs) added to them
* The start time of the course, in minutes since midnight
* */
startTime: number;
startTime!: number;
/** NOTE: Times starting and after 12 PM have an additional 720 minutes (12 hrs) added to them
* The end time of the course, in minutes since midnight
* */
endTime: number;
endTime!: number;
/** The location that the course is taught */
location?: Location;

View File

@@ -38,7 +38,7 @@ export class CourseSchedule {
if (char === 'S' && nextChar === 'U') {
day += nextChar;
}
return DAY_MAP[day];
return DAY_MAP[day as keyof typeof DAY_MAP];
})
.filter(Boolean) as Day[];
@@ -47,7 +47,7 @@ export class CourseSchedule {
.split('-')
.map(time => {
const [rawHour, rest] = time.split(':');
const [rawMinute, ampm] = rest.split(' ');
const [rawMinute, ampm] = rest?.split(' ') ?? ['', ''];
const hour = (rawHour === '12' ? 0 : Number(rawHour)) + (ampm === 'pm' ? 12 : 0);
const minute = Number(rawMinute);
@@ -56,17 +56,27 @@ export class CourseSchedule {
const location = locLine.split(' ').filter(Boolean);
if (startTime === undefined || endTime === undefined) {
throw new Error('Failed to parse time');
}
if (startTime >= endTime) {
throw new Error('Start time must be before end time');
}
if (location === undefined) {
throw new Error('Failed to parse location');
}
return new CourseMeeting({
days,
startTime,
endTime,
location: location.length
? {
building: location[0],
room: location[1],
}
: undefined,
});
location: {
building: location[0] ?? '',
room: location[1] ?? '',
},
} satisfies Serialized<CourseMeeting>);
} catch (e) {
throw new Error(`Failed to parse schedule: ${dayLine} ${timeLine} ${locLine}`);
}

View File

@@ -5,9 +5,9 @@ import type { Serialized } from 'chrome-extension-toolkit';
* A type representing an instructor for a course (who teaches it)
*/
export default class Instructor {
fullName: string;
firstName: string;
lastName: string;
fullName?: string;
firstName?: string;
lastName?: string;
middleInitial?: string;
constructor(instructor: Serialized<Instructor>) {
@@ -53,16 +53,16 @@ export default class Instructor {
return capitalize(str);
};
if (format === 'abbr') {
if (format === 'abbr' && firstName && lastName && firstName[0]) {
return `${process(firstName[0])}. ${process(lastName)}`;
}
if (format === 'full_name') {
if (format === 'full_name' && fullName) {
return process(fullName);
}
if (format === 'first_last') {
if (format === 'first_last' && firstName && lastName) {
return `${process(firstName)} ${process(lastName)}`;
}
if (format === 'last') {
if (format === 'last' && lastName) {
return process(lastName);
}

View File

@@ -42,7 +42,7 @@ export const extendedColors = {
} as const;
type NestedKeys<T> = {
[K in keyof T]: T[K] extends Record<string, any> ? `${string & K}-${string & keyof T[K]}` : never;
[K in keyof T]: T[K] extends Record<string, unknown> ? `${string & K}-${string & keyof T[K]}` : never;
}[keyof T];
/**
@@ -56,6 +56,7 @@ export type ThemeColor = NestedKeys<typeof colors>;
export type TWColorway = {
[K in keyof typeof theme.colors]: (typeof theme.colors)[K] extends Record<string, unknown> ? K : never;
}[keyof typeof theme.colors];
export type TWIndex = keyof (typeof theme.colors)[TWColorway];
/**
* Represents the colors for a course.