Aliheym / typeorm-transactional

A Transactional Method Decorator for TypeORM that uses Async Local Storage or cls-hooked to handle and propagate transactions between different repositories and service methods.
MIT License
201 stars 27 forks source link

Should return `addTransactionalDataSource` as promise #16

Closed TouchSek closed 1 year ago

TouchSek commented 1 year ago

The problem is when we are using it with Nestjs, and using dataSourceFactory, it will resolve the wrong return type. since the dataSourceFactory need to return as Promise<DataSource>

For a temporary solution I have to do like:

dataSourceFactory: (options) => {
  if (!options) {
    throw new Error('Invalid options passed')
  }

  return addTransactionalDataSource(new DataSource(options)) as unknown as Promise<DataSource>
},
neoatlan commented 1 year ago

Please put async keyword to the arrow function

chantouchsek commented 1 year ago

But async alone is not working and I don't want to disable the eslint for that kind.

neoatlan commented 1 year ago

I think your project has a rule that forbids the async keyword on functions that only have synchronous operations. How about this way? return Promise.resolve(addTransactionalDataSource(...))

TouchSek commented 1 year ago

Thanks, man it's working.