type-graphql-dataloader icon indicating copy to clipboard operation
type-graphql-dataloader copied to clipboard

TypeORM types required

Open baumandm opened this issue 4 years ago • 9 comments

Hi, I am trying to use this library without the optional TypeORM support, but building the project fails:

node_modules/type-graphql-dataloader/dist/plugins/apollo-server/ApolloServerLoaderPlugin.d.ts:1:28 - error TS2307: Cannot find module 'typeorm' or its corresponding type declarations.

1 import { Connection } from "typeorm";
                             ~~~~~~~~~

node_modules/type-graphql-dataloader/dist/decorators/typeorm/TypeormLoader.d.ts:1:28 - error TS2307: Cannot find module 'typeorm' or its corresponding type declarations.

1 import { ObjectType } from "typeorm";
                             ~~~~~~~~~

Since I'm not using TypeORM, I don't want to add a dependency on it just to provide these types. I've worked around this by creating a typeorm.d.ts file and manually stubbing those types:

declare module 'typeorm' {
  type Connection = any;
  type ObjectType<V> = any;
}

Ideally I wouldn't have to do this. This link has some possible solutions to solve this: https://stackoverflow.com/questions/54392809/how-do-i-handle-optional-peer-dependencies-when-publishing-a-typescript-package

baumandm avatar Nov 12 '20 19:11 baumandm

Thank you for the issue. I confirmed that it produces errors as pointed out. I am contemplating what would be a good solution for this problem. The suggested link would help. Thank you!

slaypni avatar Nov 13 '20 03:11 slaypni

I have changed to use import type for typeorm's types so that the errors won't happen anymore. Please see if it works with the latest version of type-graphql-datloader.

slaypni avatar Nov 15 '20 02:11 slaypni

Hi, I've tested out the latest v0.3.7 release but unfortunately it appears to have the same issue.

I'm not familiar enough with this issue to have any better suggestions. Fixing it isn't critical to me, especially since there's a workaround, so don't worry if you can't find a solution.

baumandm avatar Nov 19 '20 20:11 baumandm

@baumandm Thank you for trying it. Are you using TypeScript 3.8 or later? import type won't be supported otherwise.

slaypni avatar Nov 23 '20 10:11 slaypni

We faced the same issue on "type-graphql-dataloader": "^0.3.7". Typescript version is 4.0.3

vhatsura avatar Nov 24 '20 16:11 vhatsura

Same issue on "type-graphql-dataloader": "^0.3.7". Typescript version is 3.8.3

nudabagana avatar Apr 06 '21 12:04 nudabagana

Is it still the case at the latest version (v0.4.0)?

slaypni avatar Jun 04 '21 07:06 slaypni

Not using TypeORM either, so resolving this would help us out as well. Could still reproduce this with type-graphql-dataloader version 0.5.0, our TypeScript is "typescript": "^4.5.5".

lauriharpf@Lauris-MacBook-Pro projectdir % npx tsc
node_modules/type-graphql-dataloader/dist/decorators/typeorm/TypeormLoader.d.ts:1:33 - error TS2307: Cannot find module 'typeorm' or its corresponding type declarations.

1 import type { ObjectType } from "typeorm";
                                  ~~~~~~~~~
node_modules/type-graphql-dataloader/dist/plugins/apollo-server/ApolloServerLoaderPlugin.d.ts:2:33 - error TS2307: Cannot find module 'typeorm' or its corresponding type declarations.

2 import type { Connection } from "typeorm";
                                  ~~~~~~~~~
Found 2 errors.

lauriharpf avatar Feb 07 '22 12:02 lauriharpf

Thank you for reporting.

slaypni avatar Feb 20 '22 17:02 slaypni