Skip to content

Commit de0aaf6

Browse files
authored
chore(db-vercel-postgres): enable TypeScript strict (#11833)
same comment as in #11560, #11831, #11226: > In `src/index.ts` I see four more errors in my IDE that don't appear when I run the typecheck in the CLI with `tsc --noEmit`.
1 parent 3c4b3ee commit de0aaf6

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

packages/db-vercel-postgres/src/connect.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { DrizzleAdapter } from '@payloadcms/drizzle/types'
2-
import type { Connect } from 'payload'
2+
import type { Connect, Migration } from 'payload'
33

44
import { pushDevSchema } from '@payloadcms/drizzle'
55
import { sql, VercelPool } from '@vercel/postgres'
@@ -60,7 +60,8 @@ export const connect: Connect = async function connect(
6060
this.payload.logger.info('---- DROPPED TABLES ----')
6161
}
6262
}
63-
} catch (err) {
63+
} catch (error) {
64+
const err = error instanceof Error ? error : new Error(String(error))
6465
if (err.message?.match(/database .* does not exist/i) && !this.disableCreateDatabase) {
6566
// capitalize first char of the err msg
6667
this.payload.logger.info(
@@ -69,7 +70,7 @@ export const connect: Connect = async function connect(
6970
const isCreated = await this.createDatabase()
7071

7172
if (isCreated) {
72-
await this.connect(options)
73+
await this.connect?.(options)
7374
return
7475
}
7576
} else {
@@ -101,6 +102,6 @@ export const connect: Connect = async function connect(
101102
}
102103

103104
if (process.env.NODE_ENV === 'production' && this.prodMigrations) {
104-
await this.migrate({ migrations: this.prodMigrations })
105+
await this.migrate({ migrations: this.prodMigrations as Migration[] })
105106
}
106107
}

packages/db-vercel-postgres/src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { PgTableFn } from 'drizzle-orm/pg-core'
12
import type { DatabaseAdapterObj, Payload } from 'payload'
23

34
import {
@@ -80,10 +81,10 @@ export function vercelPostgresAdapter(args: Args = {}): DatabaseAdapterObj<Verce
8081
if (args.schemaName) {
8182
adapterSchema = pgSchema(args.schemaName)
8283
} else {
83-
adapterSchema = { enum: pgEnum, table: pgTable }
84+
adapterSchema = { enum: pgEnum, table: pgTable as unknown as PgTableFn<string> }
8485
}
8586

86-
const extensions = (args.extensions ?? []).reduce((acc, name) => {
87+
const extensions = (args.extensions ?? []).reduce<Record<string, boolean>>((acc, name) => {
8788
acc[name] = true
8889
return acc
8990
}, {})
@@ -97,6 +98,7 @@ export function vercelPostgresAdapter(args: Args = {}): DatabaseAdapterObj<Verce
9798
createExtensions,
9899
defaultDrizzleSnapshot,
99100
disableCreateDatabase: args.disableCreateDatabase ?? false,
101+
// @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve
100102
drizzle: undefined,
101103
enums: {},
102104
extensions,
@@ -123,6 +125,7 @@ export function vercelPostgresAdapter(args: Args = {}): DatabaseAdapterObj<Verce
123125
pool: undefined,
124126
poolOptions: args.pool,
125127
prodMigrations: args.prodMigrations,
128+
// @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve
126129
push: args.push,
127130
rawRelations: {},
128131
rawTables: {},
@@ -169,6 +172,7 @@ export function vercelPostgresAdapter(args: Args = {}): DatabaseAdapterObj<Verce
169172
find,
170173
findGlobal,
171174
findGlobalVersions,
175+
// @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve
172176
findOne,
173177
findVersions,
174178
init,
@@ -183,8 +187,10 @@ export function vercelPostgresAdapter(args: Args = {}): DatabaseAdapterObj<Verce
183187
packageName: '@payloadcms/db-vercel-postgres',
184188
payload,
185189
queryDrafts,
190+
// @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve
186191
rejectInitializing,
187192
requireDrizzleKit,
193+
// @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve
188194
resolveInitializing,
189195
rollbackTransaction,
190196
updateGlobal,

packages/db-vercel-postgres/tsconfig.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
{
22
"extends": "../../tsconfig.base.json",
3-
"compilerOptions": {
4-
/* TODO: remove the following lines */
5-
"strict": false,
6-
"noUncheckedIndexedAccess": false,
7-
},
83
"references": [
94
{
105
"path": "../payload"

0 commit comments

Comments
 (0)