Skip to content

Commit 6eee787

Browse files
authored
chore: add typescript-strict-plugin to the payload package for incremental file-by-file migration [skip lint] (#11133)
### What? Implement the [typescript-strict-plugin](https://github.com/allegro/typescript-strict-plugin) plugin in the payload (core) package. ### Why? 1. One strategy for incremental migration is to enable strictness rules in tsconfig, fix some errors, and push them without committing the changes to tsconfig.json. However, this is not feasible for a package as large as Payload that has over 1000 typescript errors. Until the work is done, new contributions would undo the work being done. 2. Even if no migration work is done after this PR, this change already improves the strictness of the package. 89 of the 311 files within the package already satisfy strict mode. This PR only adds a comment `@ts-strict-ignore` to files that had at least one compilation error. This way, the propagation of errors in those files is stopped. 3. New files created in the package are strict by default (this was the main improvement in version 2 of `typescript-strict-plugin`). I recommend starting the migration with this package because it is the one that almost all the others depend on. Once we finish this package, we can repeat the same strategy on another one, or use the strategy I mentioned in point 1 if the package is small. ### Note If you don't see errors in the IDE when you uncomment `// @ts-strict-ignore`, try restarting the typescript server or VSCode ### How to contribute to the migration ❤️ 1. Remove `// @ts-strict-ignore` comments from 1 or more files 2. Fix the pending errors (they should appear in your IDE's intellisense or when running `cd packages/payload` + `pnpm build:types` 3. Submit your PR! Important: You don't need to fix everything at once! Furthermore, I recommend breaking this down into very small PRs to trace potential issues later if there are any. So if you have 5 minutes, tackle a small file—every bit counts! 🤗
1 parent 30c77d8 commit 6eee787

File tree

225 files changed

+412
-22
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

225 files changed

+412
-22
lines changed

packages/payload/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"build": "rimraf .dist && rimraf tsconfig.tsbuildinfo && pnpm copyfiles && pnpm build:types && pnpm build:swc && pnpm build:esbuild",
7575
"build:esbuild": "echo skipping esbuild",
7676
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
77-
"build:types": "tsc --emitDeclarationOnly --outDir dist",
77+
"build:types": "concurrently --group \"tsc --emitDeclarationOnly --outDir dist\" \"tsc-strict\"",
7878
"clean": "rimraf -g {dist,*.tsbuildinfo}",
7979
"clean:cache": "rimraf node_modules/.cache",
8080
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
@@ -124,13 +124,15 @@
124124
"@types/pluralize": "0.0.33",
125125
"@types/uuid": "10.0.0",
126126
"@types/ws": "^8.5.10",
127+
"concurrently": "9.1.2",
127128
"copyfiles": "2.4.1",
128129
"cross-env": "7.0.3",
129130
"esbuild": "0.24.2",
130131
"graphql-http": "^1.22.0",
131132
"react-datepicker": "7.6.0",
132133
"rimraf": "6.0.1",
133-
"sharp": "0.32.6"
134+
"sharp": "0.32.6",
135+
"typescript-strict-plugin": "2.4.4"
134136
},
135137
"peerDependencies": {
136138
"graphql": "^16.8.1"

packages/payload/src/admin/RichText.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-strict-ignore
12
import type { GenericLanguages, I18n } from '@payloadcms/translations'
23
import type { JSONSchema4 } from 'json-schema'
34

packages/payload/src/admin/forms/Diff.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @ts-strict-ignore
2+
13
import type { I18nClient } from '@payloadcms/translations'
24

35
import type { ClientField, Field, FieldTypes, Tab } from '../../fields/config/types.js'

packages/payload/src/auth/cookies.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-strict-ignore
12
import type { SanitizedCollectionConfig } from './../collections/config/types.js'
23

34
type CookieOptions = {

packages/payload/src/auth/crypto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-strict-ignore
12
import crypto from 'crypto'
23

34
const algorithm = 'aes-256-ctr'

packages/payload/src/auth/endpoints/forgotPassword.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-strict-ignore
12
import { status as httpStatus } from 'http-status'
23

34
import type { PayloadHandler } from '../../config/types.js'

packages/payload/src/auth/endpoints/login.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-strict-ignore
12
import { status as httpStatus } from 'http-status'
23

34
import type { PayloadHandler } from '../../config/types.js'

packages/payload/src/auth/endpoints/me.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-strict-ignore
12
import { status as httpStatus } from 'http-status'
23

34
import type { PayloadHandler } from '../../config/types.js'

packages/payload/src/auth/endpoints/refresh.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-strict-ignore
12
import { status as httpStatus } from 'http-status'
23

34
import type { PayloadHandler } from '../../config/types.js'

packages/payload/src/auth/endpoints/registerFirstUser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-strict-ignore
12
import { status as httpStatus } from 'http-status'
23

34
import type { PayloadHandler } from '../../config/types.js'

0 commit comments

Comments
 (0)