From a9343e59bd60931fe28a9ceb946ec0856e4152f0 Mon Sep 17 00:00:00 2001 From: tsa96 Date: Thu, 2 Nov 2023 16:38:01 +0000 Subject: [PATCH] strict WIP This is making me a bit upset. I *think* we should be able ot just enable "exactOptionalPropertyTypes": true in constants/ to resolve #855 but can't get it to pass cmopile, notsure nx build backend is even using tsconfig right. Idk I just can't be bothered right now. Good luck! --- apps/backend/tsconfig.app.json | 3 +- libs/backend/decorators/tsconfig.json | 7 +---- libs/backend/dto/src/dtos/map/map.dto.ts | 4 +-- libs/backend/dto/tsconfig.json | 3 +- .../src/types/models/map/map-zones.model.ts | 28 +++++++++---------- .../src/types/models/map/map.model.ts | 3 +- libs/constants/tsconfig.json | 8 +----- libs/constants/tsconfig.lib.json | 7 +++-- libs/db/src/prisma/extended-client.ts | 2 +- libs/db/src/prisma/utils/nuke.ts | 2 +- libs/db/tsconfig.lib.json | 2 +- libs/db/tsconfig.scripts.json | 1 + .../formats/src/zone/suggestions-validator.ts | 2 +- libs/util-fn/src/expand-to-includes.ts | 4 +-- libs/util-fn/src/flatten-object.ts | 2 +- libs/util-fn/src/vector.ts | 6 ++-- tsconfig.base.json | 7 +++++ 17 files changed, 45 insertions(+), 46 deletions(-) diff --git a/apps/backend/tsconfig.app.json b/apps/backend/tsconfig.app.json index 5624020b4..aef14c59d 100644 --- a/apps/backend/tsconfig.app.json +++ b/apps/backend/tsconfig.app.json @@ -4,7 +4,8 @@ "outDir": "../../dist/out-tsc", "module": "commonjs", "types": ["node"], - "emitDecoratorMetadata": true + "emitDecoratorMetadata": true, + "strictPropertyInitialization": false }, "files": ["src/main.ts"], "include": ["src/**/*.ts"], diff --git a/libs/backend/decorators/tsconfig.json b/libs/backend/decorators/tsconfig.json index f2400abed..bb465fcd0 100644 --- a/libs/backend/decorators/tsconfig.json +++ b/libs/backend/decorators/tsconfig.json @@ -2,12 +2,7 @@ "extends": "../../../tsconfig.base.json", "compilerOptions": { "module": "commonjs", - "forceConsistentCasingInFileNames": true, - "strict": true, - "noImplicitOverride": true, - "noPropertyAccessFromIndexSignature": true, - "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true + "exactOptionalPropertyTypes": true }, "files": [], "include": [], diff --git a/libs/backend/dto/src/dtos/map/map.dto.ts b/libs/backend/dto/src/dtos/map/map.dto.ts index 224a431ce..b610b8128 100644 --- a/libs/backend/dto/src/dtos/map/map.dto.ts +++ b/libs/backend/dto/src/dtos/map/map.dto.ts @@ -89,7 +89,7 @@ export class MapDto implements MMap { get downloadURL() { return this.status === MapStatusNew.APPROVED ? `${ENDPOINT_URL}/${BUCKET}/${approvedBspPath(this.fileName)}` - : undefined; + : null; } @ApiProperty({ description: 'SHA1 hash of the BSP file', type: String }) @@ -105,7 +105,7 @@ export class MapDto implements MMap { get vmfDownloadURL() { return this.status === MapStatusNew.APPROVED && this.hasVmf ? `${ENDPOINT_URL}/${BUCKET}/${approvedVmfsPath(this.fileName)}` - : undefined; + : null; } @Exclude() diff --git a/libs/backend/dto/tsconfig.json b/libs/backend/dto/tsconfig.json index 4816de276..acf659899 100644 --- a/libs/backend/dto/tsconfig.json +++ b/libs/backend/dto/tsconfig.json @@ -3,7 +3,8 @@ "compilerOptions": { "module": "commonjs", "forceConsistentCasingInFileNames": true, - "strict": false, + "strict": true, + "strictPropertyInitialization": false, "noImplicitOverride": true, "noPropertyAccessFromIndexSignature": true, "noImplicitReturns": true, diff --git a/libs/constants/src/types/models/map/map-zones.model.ts b/libs/constants/src/types/models/map/map-zones.model.ts index 5a3661735..ccb01f318 100644 --- a/libs/constants/src/types/models/map/map-zones.model.ts +++ b/libs/constants/src/types/models/map/map-zones.model.ts @@ -1,22 +1,22 @@ import { Vector, Vector2D } from '../../utils'; +import { JsonObject } from 'type-fest'; -export interface MapZones { - // extends JsonObject { // TODO: #855 +export interface MapZones extends JsonObject { formatVersion: number; dataTimestamp: number; tracks: Tracks; volumes: Volume[]; } -export interface Tracks { - // extends JsonObject { // TODO: #855 +export interface Tracks extends JsonObject { + // TODO: #855 main: TrackEx; stages: Track[]; bonuses: TrackEx[]; } -export interface Track { - // extends JsonObject { // TODO: #855 +export interface Track extends JsonObject { + // TODO: #855 name?: string; majorOrdered?: boolean; minorRequired?: boolean; @@ -28,30 +28,28 @@ export interface Track { } export interface TrackEx extends Track { - // extends JsonObject { // TODO: #855 maxVelocity?: number; defragFlags?: number; } -export interface Segment { - // extends JsonObject { // TODO: #855 +export interface Segment extends JsonObject { + // TODO: #855 limitStartGroundSpeed: boolean; checkpoints: Zone[]; } -export interface Zone { - // extends JsonObject { // TODO: #855 +export interface Zone extends JsonObject { + // TODO: #855 volumeIndex: number; filterName?: string; } -export interface Volume { - // extends JsonObject { // TODO: #855 +export interface Volume extends JsonObject { + // TODO: #855 regions: Region[]; } -export interface Region { - // extends JsonObject { // TODO: #855 +export interface Region extends JsonObject { points: Vector2D[]; bottom: number; height: number; diff --git a/libs/constants/src/types/models/map/map.model.ts b/libs/constants/src/types/models/map/map.model.ts index f5cdec888..dd175cba3 100644 --- a/libs/constants/src/types/models/map/map.model.ts +++ b/libs/constants/src/types/models/map/map.model.ts @@ -21,7 +21,8 @@ import { MapSubmissionApproval } from './map-submission-approval.model'; */ export interface MMap extends Omit { status: MapStatusNew; - downloadURL: string; + downloadURL: string | null; + vmfDownloadURL: string | null; thumbnail?: MapImage; info?: MapInfo; // Omit then redefine zones so can be nullable - even though it's a regular diff --git a/libs/constants/tsconfig.json b/libs/constants/tsconfig.json index db7b56666..4b2225629 100644 --- a/libs/constants/tsconfig.json +++ b/libs/constants/tsconfig.json @@ -1,13 +1,7 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "module": "commonjs", - "forceConsistentCasingInFileNames": true, - "strict": true, - "noImplicitOverride": true, - "noPropertyAccessFromIndexSignature": true, - "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true + "module": "commonjs" }, "files": [], "include": [], diff --git a/libs/constants/tsconfig.lib.json b/libs/constants/tsconfig.lib.json index 33eca2c2c..cf88a1d67 100644 --- a/libs/constants/tsconfig.lib.json +++ b/libs/constants/tsconfig.lib.json @@ -3,8 +3,9 @@ "compilerOptions": { "outDir": "../../dist/out-tsc", "declaration": true, - "types": ["node"] + "types": ["node"], + "strict": true, + "exactOptionalPropertyTypes": true }, - "include": ["src/**/*.ts"], - "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"] + "include": ["src/**/*.ts"] } diff --git a/libs/db/src/prisma/extended-client.ts b/libs/db/src/prisma/extended-client.ts index 760b69590..d1845a3b3 100644 --- a/libs/db/src/prisma/extended-client.ts +++ b/libs/db/src/prisma/extended-client.ts @@ -45,7 +45,7 @@ export const PRISMA_CLIENT_EXTENSIONS = { /** * Create a User, ensuring profile and userStats entries are created. */ - async create({ args, query }) { + async create({ args, query }: any) { return query( merge( { data: { profile: { create: {} }, userStats: { create: {} } } }, diff --git a/libs/db/src/prisma/utils/nuke.ts b/libs/db/src/prisma/utils/nuke.ts index fb198ef17..9ede8256c 100644 --- a/libs/db/src/prisma/utils/nuke.ts +++ b/libs/db/src/prisma/utils/nuke.ts @@ -2,7 +2,7 @@ import { PrismaClient } from '@prisma/client'; export const nuke = async (prisma: PrismaClient) => { // Just to be extra safe... - const env = process.env.NODE_ENV; + const env = process.env['NODE_ENV']; if (!(env === 'dev' || env === 'test')) { console.error('nuke.ts: This script should never be used in production!'); process.abort(); diff --git a/libs/db/tsconfig.lib.json b/libs/db/tsconfig.lib.json index ad0ec3800..45aabd553 100644 --- a/libs/db/tsconfig.lib.json +++ b/libs/db/tsconfig.lib.json @@ -5,7 +5,7 @@ "outDir": "../../dist/out-tsc", "declaration": true, "types": ["node"], - "esModuleInterop": true + "noImplicitAny": false }, "exclude": ["src/scripts/**/*.ts"], "include": ["src/prisma/**/*.ts"] diff --git a/libs/db/tsconfig.scripts.json b/libs/db/tsconfig.scripts.json index 31c92bea9..09da75a6e 100644 --- a/libs/db/tsconfig.scripts.json +++ b/libs/db/tsconfig.scripts.json @@ -5,6 +5,7 @@ "outDir": "../../dist/out-tsc", "declaration": true, "types": ["node"], + "strict": false, "esModuleInterop": true }, "exclude": ["src/prisma/**/*.ts"], diff --git a/libs/formats/src/zone/suggestions-validator.ts b/libs/formats/src/zone/suggestions-validator.ts index 034f6c3a6..c996a2719 100644 --- a/libs/formats/src/zone/suggestions-validator.ts +++ b/libs/formats/src/zone/suggestions-validator.ts @@ -49,7 +49,7 @@ export function validateSuggestions( } } - if (IncompatibleGamemodes.get(gm).includes(gm2)) { + if (IncompatibleGamemodes.get(gm)?.includes(gm2)) { throw new SuggestionValidationError( 'Incompatible gamemodes ' + `${GamemodeName.get(gm)} and ${GamemodeName.get(gm2)} on ` + diff --git a/libs/util-fn/src/expand-to-includes.ts b/libs/util-fn/src/expand-to-includes.ts index 15ab22f09..b451f3e36 100644 --- a/libs/util-fn/src/expand-to-includes.ts +++ b/libs/util-fn/src/expand-to-includes.ts @@ -64,7 +64,7 @@ export interface ExpandToIncludesOptions< * }); */ export function expandToIncludes< - ModelInclude extends object, + ModelInclude extends Record, Expansions extends string[] = string[] >( expansions?: Expansions, @@ -73,7 +73,7 @@ export function expandToIncludes< if (!expansions || !Array.isArray(expansions) || expansions.length === 0) return undefined; - const includes: Partial = {}; + const includes: Partial> = {}; for (const expansion of expansions) { if ( diff --git a/libs/util-fn/src/flatten-object.ts b/libs/util-fn/src/flatten-object.ts index 47a74ae99..ee64664e5 100644 --- a/libs/util-fn/src/flatten-object.ts +++ b/libs/util-fn/src/flatten-object.ts @@ -11,7 +11,7 @@ function flattenRecursive( depth.counter++; } - const result = {}; + const result: Record = {}; for (const [key, value] of Object.entries(obj)) { if (isObject(value)) { for (const [innerKey, innerValue] of Object.entries( diff --git a/libs/util-fn/src/vector.ts b/libs/util-fn/src/vector.ts index c447521c7..8b43659a0 100644 --- a/libs/util-fn/src/vector.ts +++ b/libs/util-fn/src/vector.ts @@ -4,12 +4,12 @@ export const Vec = { add: (v1: V, v2: V): V => (v1.length === 2 ? [v1[0] + v2[0], v1[1] + v2[1]] - : [v1[0] + v2[0], v1[1] + v2[1], v1[2] + v2[2]]) as V, // Can't be bothered to fix "could be instantiated with different subtype" crap here. + : [v1[0] + v2[0], v1[1] + v2[1], v1[2] + (v2 as Vector)[2]]) as V, // Can't be bothered to fix "could be instantiated with different subtype" crap here. sub: (v1: V, v2: V): V => (v1.length === 2 ? [v1[0] - v2[0], v1[1] - v2[1]] - : [v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2]]) as V, + : [v1[0] - v2[0], v1[1] - v2[1], v1[2] - (v2 as Vector)[2]]) as V, len(vec: Vector | Vector2D): number { return Math.hypot(...vec); @@ -18,7 +18,7 @@ export const Vec = { dot: (v1: V, v2: V): number => v1.length === 2 ? v1[0] * v2[0] + v1[1] * v2[1] - : v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2], + : v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * (v2 as Vector)[2], /** * Get the orientation between three points diff --git a/tsconfig.base.json b/tsconfig.base.json index 7aa468c73..783ddc94b 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -5,8 +5,15 @@ "sourceMap": true, "declaration": false, "moduleResolution": "node", + "strict": true, "emitDecoratorMetadata": true, + "forceConsistentCasingInFileNames": true, "experimentalDecorators": true, + "exactOptionalPropertyTypes": false, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, "importHelpers": true, "target": "ES2022", "module": "esnext",