Skip to content

Commit

Permalink
feat: stricter tsconfig (#4073)
Browse files Browse the repository at this point in the history
* feat: stricter tsconfig

* feat: stricter tsconfig

* feat: stricter tsconfig
  • Loading branch information
belgattitude authored Jul 16, 2023
1 parent bf3dab0 commit de0b954
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 39 deletions.
6 changes: 4 additions & 2 deletions .github/actions/yarn-nm-install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ inputs:
enable-corepack:
description: 'Enable corepack'
required: false
default: 'false'
default: 'true'
skip-prisma-postinstall-generate:
description: 'Avoid prisma to automatically generate schema on postinstall'
required: false
Expand All @@ -62,7 +62,9 @@ runs:

steps:
- name: ⚙️ Enable Corepack
if: ${{ inputs.enable-corepack }} == 'true'
# Booleans aren't booleans
# https://github.com/actions/runner/issues/2238 (https://github.com/actions/runner/issues/1483)
if: inputs.enable-corepack == 'true'
shell: bash
working-directory: ${{ inputs.cwd }}
run: corepack enable
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs-app/src/components/avatar/TextAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Props = {

const mapToFullName = (nameOrFullName: string | FullName): FullName => {
if (typeof nameOrFullName === 'string') {
const [firstName, lastName] = nameOrFullName.split(' ');
const [firstName = 'F', lastName = 'L'] = nameOrFullName.split(' ');
return {
firstName,
lastName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ const GradientText = styled.span<Props>`
}
`;

const titles: [string, GradientTextBackgrounds][] = [
const titles = [
['Typescript', 'sky'],
['React', 'orange'],
['Nextjs', 'violet'],
['Prisma', 'yellow'],
['Emotion', 'fun'],
];
] satisfies [string, GradientTextBackgrounds][];

export const Jumbotron: FC = () => {
const [count, setCount] = useState(0);
Expand All @@ -104,7 +104,7 @@ export const Jumbotron: FC = () => {
One of many possibles
<br /> made with
{titles.map((title, idx) => {
const [label, grad] = titles[idx];
const [label, grad] = title;
const curr = idx === count;
return (
<GradientText
Expand Down
21 changes: 1 addition & 20 deletions apps/nextjs-app/src/features/demo/components/PoemGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
import { ArrayUtils } from '@your-org/ts-utils';
import type { FC } from 'react';
import type { SearchPoems } from '@/backend/features/poem/SearchPoems';
import { PoemCard } from './PoemCard';

const waterImages = new Array(25).fill('').map((img, idx) => {
const index = String(idx + 1).padStart(2, '0');
return `/shared-assets/images/water/water-${index}.jpg`;
});

export const PoemGrid: FC<{ poems: SearchPoems; children?: never }> = (
props
) => {
export const PoemGrid: FC<{ poems: SearchPoems }> = (props) => {
const { poems } = props;
let images = waterImages;
return (
<div className="flex flex-wrap">
{poems.map((poem) => {
const randomImg = ArrayUtils.getRandom(images);
const defaultImg = `/_next/image?url=${encodeURIComponent(
randomImg
)}&w=640&q=85`;
images =
images.length < 1
? waterImages
: ArrayUtils.removeItem(images, randomImg);

const unsplashImg = `https://source.unsplash.com/random/640x480?${(
poem.keywords ?? []
)
Expand All @@ -42,7 +24,6 @@ export const PoemGrid: FC<{ poems: SearchPoems; children?: never }> = (
author={poem.author}
keywords={poem.keywords}
img={unsplashImg}
defaultImg={defaultImg}
/>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs-app/src/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Props = DocumentProps & {
};

class MyDocument extends Document<Props> {
render() {
override render() {
const locale = this.props.locale ?? defaultLocale;

return (
Expand Down
4 changes: 2 additions & 2 deletions packages/db-main-prisma/src/prisma-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class PrismaManager {
PrismaManager.instances ??= {};
PrismaManager.instances[instanceKey] = prismaClientFactory();
}
return PrismaManager.instances[instanceKey];
return PrismaManager.instances[instanceKey] as PrismaClient;
} else {
// PrismaClient is attached to the `global` object in development to prevent
// exhausting your database connection limit.
Expand All @@ -43,7 +43,7 @@ export class PrismaManager {
'[PrismaFactory.createDevSafeInstance]: Dev instance created and preserved globally.'
);
}
return global.__PRISMA_INSTANCES__[instanceKey];
return global.__PRISMA_INSTANCES__[instanceKey] as PrismaClient;
}
}
}
6 changes: 4 additions & 2 deletions packages/ts-utils/src/array/ArrayUtils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { getRandomInt } from '../random/index';
import type { NonEmptyArray } from '../types';

export class ArrayUtils {
static getRandom<T>(items: T[]): T {
return items[getRandomInt(0, items.length - 1)];
static getRandom<T>(items: NonEmptyArray<T>): T {
if (items.length === 1) return items[0];
return items[getRandomInt(0, items.length - 1)] as unknown as T;
}

static removeItem<T>(arr: T[], item: T): T[] {
Expand Down
7 changes: 4 additions & 3 deletions packages/ts-utils/src/array/__tests__/ArrayUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { NonEmptyArray } from '../../types';
import { ArrayUtils } from '../ArrayUtils';

describe('ArrayUtils', () => {
Expand All @@ -11,8 +12,8 @@ describe('ArrayUtils', () => {
});
describe('getRandom', () => {
it('should return different elements', () => {
const arr = ['cool', 'test', true, 0];
const results: typeof arr = [];
const arr = ['cool', 'test', true, 0] satisfies NonEmptyArray<any>;
const results: NonEmptyArray<(typeof arr)[number]> = [0];
const maxIterations = 20;
for (let i = 0; i < maxIterations; i++) {
results.push(ArrayUtils.getRandom(arr));
Expand All @@ -21,7 +22,7 @@ describe('ArrayUtils', () => {
expect(unique.length).toBeGreaterThan(1);
});
it('should always return an element from the array', () => {
const arr = ['cool', 'test', true, 0];
const arr = ['cool', 'test', true, 0] satisfies NonEmptyArray<any>;
const maxIterations = 20;
for (let i = 0; i < maxIterations; i++) {
const el = ArrayUtils.getRandom(arr);
Expand Down
6 changes: 6 additions & 0 deletions packages/ts-utils/src/typeguards/typeguards.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { NonEmptyArray } from '../types';

export type IsoDateString = string;
export const isIsoDateString = (dateStr: unknown): dateStr is IsoDateString => {
if (
Expand All @@ -14,6 +16,10 @@ export const isIsoDateString = (dateStr: unknown): dateStr is IsoDateString => {
}
};

export const isNonEmptyArray = <T>(v: unknown): v is NonEmptyArray<T> => {
return Array.isArray(v) && v.length > 0;
};

export const isNonEmptyString = (v: unknown, trim = true): v is string => {
return typeof v === 'string' && (trim ? v.trim() : v).length > 0;
};
Expand Down
1 change: 1 addition & 0 deletions packages/ts-utils/src/types/NonEmptyArray.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type NonEmptyArray<T> = [T, ...T[]];
1 change: 1 addition & 0 deletions packages/ts-utils/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export type { UnPromisify } from './Unpromisify';
export type { NonEmptyArray } from './NonEmptyArray';
2 changes: 1 addition & 1 deletion packages/ui-lib/src/ux/text/GradientText.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const AnimatedExample: StoryObj<typeof GradientText> = {
>
Typescript
{titles.map((title, idx) => {
const [label, grad] = titles[idx];
const [label, grad] = title;
const curr = idx === activeIdx;
return (
<GradientText
Expand Down
12 changes: 8 additions & 4 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"moduleResolution": "node",
"verbatimModuleSyntax": true,
"strict": true,
"useUnknownInCatchVariables": true,
"verbatimModuleSyntax": true,
"noImplicitOverride": true,
"noUncheckedIndexedAccess": true,
"allowUnreachableCode": false,
"noFallthroughCasesInSwitch": true,
"forceConsistentCasingInFileNames": true,
"allowJs": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"incremental": true,
"newLine": "lf"
},
Expand Down

2 comments on commit de0b954

@vercel
Copy link

@vercel vercel bot commented on de0b954 Jul 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

monorepo-nextjs-app – ./apps/nextjs-app

monorepo-nextjs-app-git-main-belgattitude.vercel.app
monorepo-nextjs-app.vercel.app
monorepo-nextjs-app-belgattitude.vercel.app

@vercel
Copy link

@vercel vercel bot commented on de0b954 Jul 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

monorepo-vite-app – ./apps/vite-app

monorepo-vite-app-git-main-belgattitude.vercel.app
monorepo-vite-app-belgattitude.vercel.app
monorepo-vite-app.vercel.app

Please sign in to comment.