Repository navigation
Conversation
…ptionalPropertyTypes The transaction options were derived from the optional second parameter of `transaction()`, so they included `undefined`. With exactOptionalPropertyTypes enabled, that made the adapter fail to match TransactionalAdapter and typed TransactionHost#tx as `never`. Closes Papooch#695
…alPropertyTypes Drop `undefined` from the options derived from `$transaction()`, and spell out the return type of optionsFactory so the emitted declaration does not carry `wrapWithNestedTransaction?: ... | undefined`. Either one made the adapter fail to match TransactionalAdapter under exactOptionalPropertyTypes, which typed TransactionHost#tx as `never`.
…onalPropertyTypes Drop `undefined` from the options derived from the optional second parameter of `Connection#transaction()`. Under exactOptionalPropertyTypes it made the adapter fail to match TransactionalAdapter, which typed TransactionHost#tx as `never`.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #695
What
With
exactOptionalPropertyTypesenabled,TransactionHost#txis typed asneverfor the Drizzle, Prisma and Mongoose adapters.Why
Parameters<...['transaction']>[1]. That parameter is optional, so the type includesundefined.defaultTxOptions?: Partial<TOptions | undefined>then doesn't matchTransactionalAdapter'sdefaultTxOptions?: Partial<TOptions>, soTTxFromAdapterresolves tonever. Wrapping the derived type inNonNullablefixes it.TransactionHostalways merges the options into an object ({ ...defaultTxOptions, ...options }), so an adapter never receivesundefined.optionsFactoryreturn type. Because ofsqlFlavor ? fn : undefined, the emitted.d.tscontainswrapWithNestedTransaction?: (...) | undefined. That also fails to match the interface underexactOptionalPropertyTypes, even after the options fix. Spelling out the return type asTransactionalAdapterOptions<...>makes the declaration match. Runtime behaviour is the same, becauseTransactionHoststill checkstypeof wrapWithNestedTransaction === 'function'.I checked the other adapters (knex, kysely, typeorm, pg-promise, mongodb) against their built declarations with
exactOptionalPropertyTypes. They are not affected.Tests
I added a
*-types.spec.tsto each of the three adapters. Each spec uses the TypeScript compiler API to type-check a short consumer snippet that imports the packages by name, so it runs against the built declarations a user gets. The snippet usestxHost.tx,withTransaction(options, ...)anddefaultTxOptions. Each spec checks it withexactOptionalPropertyTypeson and off and expects no errors. The specs need no database. Like the other suites, they expectyarn buildto have run first, which CI does.Before the fix (
exactOptionalPropertyTypes: truecase):After the fix, all six cases pass.
Commands run:
The new type specs and the Drizzle sync (better-sqlite3) suite pass. I couldn't run the Postgres-backed Drizzle and Prisma suites locally because they need Docker. The changes to those packages only affect types.