graphql-code-generator: `mappers` option results in duplicate identifiers in the generated TS file
having some types remapped using the mappers option leaves both the new (imported) type and the old (generated) type in the generated file.
apparently it wasn’t an issue before, but now the new Typescript does not like that and I get
TS2440: Import declaration conflicts with local declaration
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 6
- Comments: 21 (5 by maintainers)
Is there maybe an option to automagically alias every mapper?
So for example a config like;
Would generate an import like;
@helios1138 @janhartmann You can try to import those like below;
Available in
v1.10.0.PR #2957 seems to do the correct job as it’s outputting the correct information.
But somehow, the actual file output does not contain the alias:
Hi, I’m not sure this actually works - or maybe I’m just missing something… I’m on version 1.9.1. Let’s say I have the following structure:
This results in the following line at the beginning of the generated
types.ts:The
User asbit of the import seems to be somehow lost in translation… which makes the result quite broken. Any idea what am I doing wrong? Pretty please, with cherry on top?@lachenmayer Could you try using aliases with the following canary version?
1.8.4-alpha-d88e5f9a.53+d88e5f9a@ardatan this does indeed work, thanks. Though it looks more like a workaround since it makes the config a bit harder to read and results in duplicates, for example, if generics are also used
In any case, if
import asis not an option at this moment, I think it would be good if the workaround you mentioned would be added to the docs since I believe it’s a pretty common case when database types and graphql types have the same name.Currently, as far as I see, the docs only mention
path#Nameway of importingI am hitting this issue as well, when upgrading to TypeScript 3.7.2
The
as Xwould be helpful or something likeimport * as Something from "./something".