vojtechhabarta/typescript-generator

Usage of moduleDependencies breaks typing of map of enum and repeat inherited fields

CedricMtta opened this issue · 0 comments

Hello,

FIrst of all, thanks for this project, it is much appreciated.

I may have missed the solution to my problem in the doc, but here is my issue:

I am using typescript-generator version 3.2.1263 with gradle.

I created one gradle sub module named "common-generator" that aims to create a file with common typescript classes enums for our front-end.

I defined for it the following configuration:

generateTypeScript {
  jsonLibrary = 'jackson2'
  classes = [
    ...
  ]
  outputKind = 'module'
  outputFileType = 'implementationFile'
  outputFile = '../<front end path>/common/models/common-backend.model.ts'
  generateInfoJson = 'true'
  noFileComment = 'true'
  sortDeclarations = 'true'
  sortTypeDeclarations = 'true'
  excludeClasses = [
    'java.io.Serializable',
    'org.springframework.data.util.Streamable',
    'org.springframework.data.domain.Chunk'
  ]
  mapEnum = 'asEnum'
  nonConstEnums = 'true'
  requiredAnnotations = ['javax.validation.constraints.NotNull']
}

So far so good, I obtain the expected common-backend.model.ts.
That is to say, I have some java fields defined as EnumMap

private Map<Language, String> synonymLabels;

that are well typed in typescript

synonymLabels?: { [P in Language]?: string };

Then, I created another gradle sub module named "businessA-generator" that aims to create a file with specific typescript classes for one of our front-end module.

I defined for it the following configuration:

generateTypeScript {
  jsonLibrary = 'jackson2'
  classes = [
...
  ]
  outputKind = 'module'
  outputFileType = 'implementationFile'
  outputFile = '../<front end path>/businessA/models/businessA-backend.model.ts'
  noFileComment = 'true'
  sortDeclarations = 'true'
  sortTypeDeclarations = 'true'
  moduleDependencies = [
    cz.habarta.typescript.generator.ModuleDependency.module('@shared/common/models/common-backend.model', 'common', new File('<front end path>/common/models/typescript-generator-info.json'), null, null)
  ]
  excludeClasses = [
    'java.io.Serializable',
    'org.springframework.data.util.Streamable'
  ]
  mapEnum = 'asEnum'
  nonConstEnums = 'true'
  requiredAnnotations = ['javax.validation.constraints.NotNull']
}

Here comes my issue.
Map of enums are now typed like this:

synonymLabels?: { [index: string]: string };

Whereas I would have expected:

synonymLabels?: { [P in common.Language]: string };

Other issue, but less impactful, in case of inheritance, the properties of the mother class are repeated.
For instance, the following java code

public interface Taggable {
  TagListDto getTagListDto();
}

public class OutComeTagGroup implements Taggable {

  private List<String> otherTags = new ArrayList<>();
  private List<String> resultCategoryTags = new ArrayList<>();
public TagListDto getTagListDto() {...}
}

Is generated into

(from common file)
export interface Taggable {
    tagListDto?: TagListDto;
}

(from another business file)
export interface OutComeTagGroup extends common.Taggable {
    otherTags?: string[];
    resultCategoryTags?: string[];
    tagListDto?: common.TagListDto;
}

Whereas I would expect

export interface OutComeTagGroup extends common.Taggable {
    otherTags?: string[];
    resultCategoryTags?: string[];
}

Inheritance taking place in the same typescript generated file doesn't have this issue.

Have I missed something in the plugin configuration, or is there an issue in typescript-generator ?

Thanks in advance for your help.

I wish you a nice day :)