Skip to content

Commit

Permalink
strict WIP
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
tsa96 committed Nov 2, 2023
1 parent 8d3d5d2 commit a9343e5
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 46 deletions.
3 changes: 2 additions & 1 deletion apps/backend/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
7 changes: 1 addition & 6 deletions libs/backend/decorators/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
4 changes: 2 additions & 2 deletions libs/backend/dto/src/dtos/map/map.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand All @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion libs/backend/dto/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": false,
"strict": true,
"strictPropertyInitialization": false,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
Expand Down
28 changes: 13 additions & 15 deletions libs/constants/src/types/models/map/map-zones.model.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion libs/constants/src/types/models/map/map.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { MapSubmissionApproval } from './map-submission-approval.model';
*/
export interface MMap extends Omit<PrismaMMap, 'thumbnailID' | 'zones'> {
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
Expand Down
8 changes: 1 addition & 7 deletions libs/constants/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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": [],
Expand Down
7 changes: 4 additions & 3 deletions libs/constants/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
2 changes: 1 addition & 1 deletion libs/db/src/prisma/extended-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {} } } },
Expand Down
2 changes: 1 addition & 1 deletion libs/db/src/prisma/utils/nuke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion libs/db/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node"],
"esModuleInterop": true
"noImplicitAny": false
},
"exclude": ["src/scripts/**/*.ts"],
"include": ["src/prisma/**/*.ts"]
Expand Down
1 change: 1 addition & 0 deletions libs/db/tsconfig.scripts.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node"],
"strict": false,
"esModuleInterop": true
},
"exclude": ["src/prisma/**/*.ts"],
Expand Down
2 changes: 1 addition & 1 deletion libs/formats/src/zone/suggestions-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ` +
Expand Down
4 changes: 2 additions & 2 deletions libs/util-fn/src/expand-to-includes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export interface ExpandToIncludesOptions<
* });
*/
export function expandToIncludes<
ModelInclude extends object,
ModelInclude extends Record<string, unknown>,
Expansions extends string[] = string[]
>(
expansions?: Expansions,
Expand All @@ -73,7 +73,7 @@ export function expandToIncludes<
if (!expansions || !Array.isArray(expansions) || expansions.length === 0)
return undefined;

const includes: Partial<ModelInclude> = {};
const includes: Partial<Record<string, unknown>> = {};

for (const expansion of expansions) {
if (
Expand Down
2 changes: 1 addition & 1 deletion libs/util-fn/src/flatten-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function flattenRecursive(
depth.counter++;
}

const result = {};
const result: Record<string, Primitive | unknown[]> = {};
for (const [key, value] of Object.entries(obj)) {
if (isObject(value)) {
for (const [innerKey, innerValue] of Object.entries(
Expand Down
6 changes: 3 additions & 3 deletions libs/util-fn/src/vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ export const Vec = {
add: <V extends Vector | Vector2D>(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: <V extends Vector | Vector2D>(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);
Expand All @@ -18,7 +18,7 @@ export const Vec = {
dot: <V extends Vector | Vector2D>(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
Expand Down
7 changes: 7 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit a9343e5

Please sign in to comment.