From 085c1d0cac93288f3e87733427a99c452633a16c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Jablo=C3=B1ski?= <43938777+GermanJablo@users.noreply.github.com> Date: Tue, 14 Jan 2025 18:39:40 -0300 Subject: [PATCH] chore: make TypeScript strict by default in packages and 7 packages stricter (#10579) This PR modifies `tsconfig.base.json` by setting the following strictness properties to true: `strict`, `noUncheckedIndexedAccess` and `noImplicitOverride`. In packages where compilation errors were observed, these settings were opted out, and TODO comments were added to make it easier to track the roadmap for converting everything to strict mode. The following packages now have increased strictness, which prevents new errors from being accidentally introduced: - storage-vercel-blob - storage-s3* - storage-gcs - plugin-sentry - payload-cloud* - email-resend* - email-nodemailer* *These packages already had `strict: true`, but now have `noUncheckedIndexedAccess` and `noImplicitOverride`. Note that this only affects the `/packages` folder, but not `/templates`, `/test` or `/examples` which have a different `tsconfig`. --- packages/create-payload-app/tsconfig.json | 4 +++- packages/db-mongodb/tsconfig.json | 6 ++++++ packages/db-postgres/tsconfig.json | 6 ++++++ packages/db-sqlite/tsconfig.json | 6 ++++++ packages/db-vercel-postgres/tsconfig.json | 6 ++++++ packages/drizzle/tsconfig.json | 6 ++++++ packages/email-nodemailer/tsconfig.json | 3 --- packages/email-resend/tsconfig.json | 3 --- packages/graphql/tsconfig.json | 6 ++++++ packages/live-preview-react/tsconfig.json | 6 ++++++ packages/live-preview-vue/tsconfig.json | 6 ++++++ packages/live-preview/tsconfig.json | 6 ++++++ packages/next/tsconfig.json | 6 ++++++ packages/payload-cloud/tsconfig.json | 3 --- packages/payload/tsconfig.json | 6 ++++++ packages/plugin-cloud-storage/tsconfig.json | 6 ++++++ packages/plugin-form-builder/tsconfig.json | 6 ++++++ packages/plugin-nested-docs/tsconfig.json | 6 ++++++ packages/plugin-redirects/tsconfig.json | 6 ++++++ packages/plugin-search/tsconfig.json | 6 ++++++ packages/plugin-seo/tsconfig.json | 6 ++++++ packages/plugin-stripe/tsconfig.json | 6 ++++++ packages/richtext-lexical/tsconfig.json | 6 +++--- packages/richtext-slate/tsconfig.json | 7 ++++++- packages/storage-azure/tsconfig.json | 5 ++++- packages/storage-gcs/tsconfig.json | 1 - packages/storage-uploadthing/tsconfig.json | 6 ++++++ packages/translations/tsconfig.json | 6 ++++++ packages/ui/tsconfig.json | 6 ++++++ tsconfig.base.json | 6 +++++- 30 files changed, 147 insertions(+), 17 deletions(-) diff --git a/packages/create-payload-app/tsconfig.json b/packages/create-payload-app/tsconfig.json index 3c0293c57..c9d8c5e06 100644 --- a/packages/create-payload-app/tsconfig.json +++ b/packages/create-payload-app/tsconfig.json @@ -1,6 +1,8 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "strict": true + /* TODO: remove the following lines */ + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, }, } diff --git a/packages/db-mongodb/tsconfig.json b/packages/db-mongodb/tsconfig.json index a181cd4bf..680d5fb20 100644 --- a/packages/db-mongodb/tsconfig.json +++ b/packages/db-mongodb/tsconfig.json @@ -1,4 +1,10 @@ { "extends": "../../tsconfig.base.json", + "compilerOptions": { + /* TODO: remove the following lines */ + "strict": false, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, + }, "references": [{ "path": "../payload" }, { "path": "../translations" }] } diff --git a/packages/db-postgres/tsconfig.json b/packages/db-postgres/tsconfig.json index 760627a1b..513cf23b5 100644 --- a/packages/db-postgres/tsconfig.json +++ b/packages/db-postgres/tsconfig.json @@ -1,5 +1,11 @@ { "extends": "../../tsconfig.base.json", + "compilerOptions": { + /* TODO: remove the following lines */ + "strict": false, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, + }, "references": [ { "path": "../payload" diff --git a/packages/db-sqlite/tsconfig.json b/packages/db-sqlite/tsconfig.json index 760627a1b..513cf23b5 100644 --- a/packages/db-sqlite/tsconfig.json +++ b/packages/db-sqlite/tsconfig.json @@ -1,5 +1,11 @@ { "extends": "../../tsconfig.base.json", + "compilerOptions": { + /* TODO: remove the following lines */ + "strict": false, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, + }, "references": [ { "path": "../payload" diff --git a/packages/db-vercel-postgres/tsconfig.json b/packages/db-vercel-postgres/tsconfig.json index 760627a1b..513cf23b5 100644 --- a/packages/db-vercel-postgres/tsconfig.json +++ b/packages/db-vercel-postgres/tsconfig.json @@ -1,5 +1,11 @@ { "extends": "../../tsconfig.base.json", + "compilerOptions": { + /* TODO: remove the following lines */ + "strict": false, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, + }, "references": [ { "path": "../payload" diff --git a/packages/drizzle/tsconfig.json b/packages/drizzle/tsconfig.json index a181cd4bf..680d5fb20 100644 --- a/packages/drizzle/tsconfig.json +++ b/packages/drizzle/tsconfig.json @@ -1,4 +1,10 @@ { "extends": "../../tsconfig.base.json", + "compilerOptions": { + /* TODO: remove the following lines */ + "strict": false, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, + }, "references": [{ "path": "../payload" }, { "path": "../translations" }] } diff --git a/packages/email-nodemailer/tsconfig.json b/packages/email-nodemailer/tsconfig.json index 9f2129e17..45209999a 100644 --- a/packages/email-nodemailer/tsconfig.json +++ b/packages/email-nodemailer/tsconfig.json @@ -1,7 +1,4 @@ { "extends": "../../tsconfig.base.json", - "compilerOptions": { - "strict": true - }, "references": [{ "path": "../payload" }] } diff --git a/packages/email-resend/tsconfig.json b/packages/email-resend/tsconfig.json index 9f2129e17..45209999a 100644 --- a/packages/email-resend/tsconfig.json +++ b/packages/email-resend/tsconfig.json @@ -1,7 +1,4 @@ { "extends": "../../tsconfig.base.json", - "compilerOptions": { - "strict": true - }, "references": [{ "path": "../payload" }] } diff --git a/packages/graphql/tsconfig.json b/packages/graphql/tsconfig.json index 45209999a..2df4c5635 100644 --- a/packages/graphql/tsconfig.json +++ b/packages/graphql/tsconfig.json @@ -1,4 +1,10 @@ { "extends": "../../tsconfig.base.json", + "compilerOptions": { + /* TODO: remove the following lines */ + "strict": false, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, + }, "references": [{ "path": "../payload" }] } diff --git a/packages/live-preview-react/tsconfig.json b/packages/live-preview-react/tsconfig.json index 45209999a..2df4c5635 100644 --- a/packages/live-preview-react/tsconfig.json +++ b/packages/live-preview-react/tsconfig.json @@ -1,4 +1,10 @@ { "extends": "../../tsconfig.base.json", + "compilerOptions": { + /* TODO: remove the following lines */ + "strict": false, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, + }, "references": [{ "path": "../payload" }] } diff --git a/packages/live-preview-vue/tsconfig.json b/packages/live-preview-vue/tsconfig.json index 0c88df292..595b81bdb 100644 --- a/packages/live-preview-vue/tsconfig.json +++ b/packages/live-preview-vue/tsconfig.json @@ -1,4 +1,10 @@ { "extends": "../../tsconfig.base.json", + "compilerOptions": { + /* TODO: remove the following lines */ + "strict": false, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, + }, "references": [{ "path": "../payload" }] // db-mongodb depends on payload } diff --git a/packages/live-preview/tsconfig.json b/packages/live-preview/tsconfig.json index 45209999a..2df4c5635 100644 --- a/packages/live-preview/tsconfig.json +++ b/packages/live-preview/tsconfig.json @@ -1,4 +1,10 @@ { "extends": "../../tsconfig.base.json", + "compilerOptions": { + /* TODO: remove the following lines */ + "strict": false, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, + }, "references": [{ "path": "../payload" }] } diff --git a/packages/next/tsconfig.json b/packages/next/tsconfig.json index dd1530595..5f7685d4e 100644 --- a/packages/next/tsconfig.json +++ b/packages/next/tsconfig.json @@ -1,5 +1,11 @@ { "extends": "../../tsconfig.base.json", + "compilerOptions": { + /* TODO: remove the following lines */ + "strict": false, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, + }, "references": [ { "path": "../payload" }, { "path": "../ui" }, diff --git a/packages/payload-cloud/tsconfig.json b/packages/payload-cloud/tsconfig.json index 9f2129e17..45209999a 100644 --- a/packages/payload-cloud/tsconfig.json +++ b/packages/payload-cloud/tsconfig.json @@ -1,7 +1,4 @@ { "extends": "../../tsconfig.base.json", - "compilerOptions": { - "strict": true - }, "references": [{ "path": "../payload" }] } diff --git a/packages/payload/tsconfig.json b/packages/payload/tsconfig.json index d4811ddd5..3553827af 100644 --- a/packages/payload/tsconfig.json +++ b/packages/payload/tsconfig.json @@ -1,4 +1,10 @@ { "extends": "../../tsconfig.base.json", + "compilerOptions": { + /* TODO: remove the following lines */ + "strict": false, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, + }, "references": [{ "path": "../translations" }] } diff --git a/packages/plugin-cloud-storage/tsconfig.json b/packages/plugin-cloud-storage/tsconfig.json index 45209999a..2df4c5635 100644 --- a/packages/plugin-cloud-storage/tsconfig.json +++ b/packages/plugin-cloud-storage/tsconfig.json @@ -1,4 +1,10 @@ { "extends": "../../tsconfig.base.json", + "compilerOptions": { + /* TODO: remove the following lines */ + "strict": false, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, + }, "references": [{ "path": "../payload" }] } diff --git a/packages/plugin-form-builder/tsconfig.json b/packages/plugin-form-builder/tsconfig.json index dd036fd84..45b2f18fb 100644 --- a/packages/plugin-form-builder/tsconfig.json +++ b/packages/plugin-form-builder/tsconfig.json @@ -1,4 +1,10 @@ { "extends": "../../tsconfig.base.json", + "compilerOptions": { + /* TODO: remove the following lines */ + "strict": false, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, + }, "references": [{ "path": "../payload" }, { "path": "../ui" }] } diff --git a/packages/plugin-nested-docs/tsconfig.json b/packages/plugin-nested-docs/tsconfig.json index 45209999a..2df4c5635 100644 --- a/packages/plugin-nested-docs/tsconfig.json +++ b/packages/plugin-nested-docs/tsconfig.json @@ -1,4 +1,10 @@ { "extends": "../../tsconfig.base.json", + "compilerOptions": { + /* TODO: remove the following lines */ + "strict": false, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, + }, "references": [{ "path": "../payload" }] } diff --git a/packages/plugin-redirects/tsconfig.json b/packages/plugin-redirects/tsconfig.json index 45209999a..2df4c5635 100644 --- a/packages/plugin-redirects/tsconfig.json +++ b/packages/plugin-redirects/tsconfig.json @@ -1,4 +1,10 @@ { "extends": "../../tsconfig.base.json", + "compilerOptions": { + /* TODO: remove the following lines */ + "strict": false, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, + }, "references": [{ "path": "../payload" }] } diff --git a/packages/plugin-search/tsconfig.json b/packages/plugin-search/tsconfig.json index fb2118286..868922448 100644 --- a/packages/plugin-search/tsconfig.json +++ b/packages/plugin-search/tsconfig.json @@ -1,4 +1,10 @@ { "extends": "../../tsconfig.base.json", + "compilerOptions": { + /* TODO: remove the following lines */ + "strict": false, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, + }, "references": [{ "path": "../payload" }, { "path": "../ui" }, { "path": "../next" }] } diff --git a/packages/plugin-seo/tsconfig.json b/packages/plugin-seo/tsconfig.json index fb2118286..868922448 100644 --- a/packages/plugin-seo/tsconfig.json +++ b/packages/plugin-seo/tsconfig.json @@ -1,4 +1,10 @@ { "extends": "../../tsconfig.base.json", + "compilerOptions": { + /* TODO: remove the following lines */ + "strict": false, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, + }, "references": [{ "path": "../payload" }, { "path": "../ui" }, { "path": "../next" }] } diff --git a/packages/plugin-stripe/tsconfig.json b/packages/plugin-stripe/tsconfig.json index fb2118286..868922448 100644 --- a/packages/plugin-stripe/tsconfig.json +++ b/packages/plugin-stripe/tsconfig.json @@ -1,4 +1,10 @@ { "extends": "../../tsconfig.base.json", + "compilerOptions": { + /* TODO: remove the following lines */ + "strict": false, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, + }, "references": [{ "path": "../payload" }, { "path": "../ui" }, { "path": "../next" }] } diff --git a/packages/richtext-lexical/tsconfig.json b/packages/richtext-lexical/tsconfig.json index c2fd8ec34..3a7de719d 100644 --- a/packages/richtext-lexical/tsconfig.json +++ b/packages/richtext-lexical/tsconfig.json @@ -1,9 +1,9 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "strictNullChecks": true, - "noImplicitAny": true, - "strict": true + /* TODO: remove the following lines */ + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false }, "references": [ { "path": "../payload" }, diff --git a/packages/richtext-slate/tsconfig.json b/packages/richtext-slate/tsconfig.json index c2fc6e86b..1464398dc 100644 --- a/packages/richtext-slate/tsconfig.json +++ b/packages/richtext-slate/tsconfig.json @@ -6,7 +6,12 @@ "emitDeclarationOnly": true, "outDir": "./dist" /* Specify an output folder for all emitted files. */, "rootDir": "./src" /* Specify the root folder within your source files. */, - "jsx": "react-jsx" + "jsx": "react-jsx", + + /* TODO: remove the following lines */ + "strict": false, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, }, "exclude": [ "dist", diff --git a/packages/storage-azure/tsconfig.json b/packages/storage-azure/tsconfig.json index ecb0fe770..b8eda6d59 100644 --- a/packages/storage-azure/tsconfig.json +++ b/packages/storage-azure/tsconfig.json @@ -6,7 +6,10 @@ "emitDeclarationOnly": true, "outDir": "./dist" /* Specify an output folder for all emitted files. */, "rootDir": "./src" /* Specify the root folder within your source files. */, - "strict": true + + /* TODO: remove the following lines */ + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, }, "exclude": ["dist", "node_modules"], "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.d.ts", "src/**/*.json"], diff --git a/packages/storage-gcs/tsconfig.json b/packages/storage-gcs/tsconfig.json index ecb0fe770..459842564 100644 --- a/packages/storage-gcs/tsconfig.json +++ b/packages/storage-gcs/tsconfig.json @@ -6,7 +6,6 @@ "emitDeclarationOnly": true, "outDir": "./dist" /* Specify an output folder for all emitted files. */, "rootDir": "./src" /* Specify the root folder within your source files. */, - "strict": true }, "exclude": ["dist", "node_modules"], "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.d.ts", "src/**/*.json"], diff --git a/packages/storage-uploadthing/tsconfig.json b/packages/storage-uploadthing/tsconfig.json index 48567c8ce..803fd1e43 100644 --- a/packages/storage-uploadthing/tsconfig.json +++ b/packages/storage-uploadthing/tsconfig.json @@ -1,4 +1,10 @@ { "extends": "../../tsconfig.base.json", + "compilerOptions": { + /* TODO: remove the following lines */ + "strict": false, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, + }, "references": [{ "path": "../payload" }, { "path": "../plugin-cloud-storage" }] } diff --git a/packages/translations/tsconfig.json b/packages/translations/tsconfig.json index 96a27d9cc..83ccf9536 100644 --- a/packages/translations/tsconfig.json +++ b/packages/translations/tsconfig.json @@ -1,3 +1,9 @@ { "extends": "../../tsconfig.base.json", + "compilerOptions": { + /* TODO: remove the following lines */ + "strict": false, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, + } } diff --git a/packages/ui/tsconfig.json b/packages/ui/tsconfig.json index a181cd4bf..680d5fb20 100644 --- a/packages/ui/tsconfig.json +++ b/packages/ui/tsconfig.json @@ -1,4 +1,10 @@ { "extends": "../../tsconfig.base.json", + "compilerOptions": { + /* TODO: remove the following lines */ + "strict": false, + "noUncheckedIndexedAccess": false, + "noImplicitOverride": false, + }, "references": [{ "path": "../payload" }, { "path": "../translations" }] } diff --git a/tsconfig.base.json b/tsconfig.base.json index 23c517dc7..f1309a2ad 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1,5 +1,10 @@ { "compilerOptions": { + /* Strictness */ + "strict": true, + "noUncheckedIndexedAccess": true, + "noImplicitOverride": true, + "composite": true, "declaration": true, "declarationMap": true, @@ -21,7 +26,6 @@ "types": ["jest", "node", "@types/jest"], "incremental": true, "isolatedModules": true, - "strict": false, "plugins": [ { "name": "next"