Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic type parameters not resolved properly #380

Closed
Mobe91 opened this issue Jun 28, 2019 · 6 comments
Closed

Generic type parameters not resolved properly #380

Mobe91 opened this issue Jun 28, 2019 · 6 comments
Labels

Comments

@Mobe91
Copy link

Mobe91 commented Jun 28, 2019

Given to following class hierarchy:

public interface IdView<T extends Serializable> {
    T getId();
}

public interface Entity1IdView extends IdView<UUID> {
}

public abstract class Entity1View implements Entity1IdView {
  private String name;

  public String getName() { return name; }
}

Yields the following typescript definitions:

export interface Serializable {
}
export interface Entity1IdView extends IdView<string> {
}
export class Entity1View implements Entity1IdView {
    id: T;
    name: string;
}

Apparently, the type parameter T is not resolved correctly for the declaration of the id field in Entity1View.

@olegshtch
Copy link
Contributor

cz.habarta.typescript.generator.compiler.ModelCompiler.getTypeParameters ignores bounds. But it possible to have unknown class here, so it should use data from Model, which discovers new classes.

@olegshtch
Copy link
Contributor

@Mobe91 Could you try #389 ?

@vojtechhabarta
Copy link
Owner

@olegshtch I tried #389 with mentioned example, here is the generated output:

export class Entity1View implements Entity1IdView {
    id: T;  // needs to be resolved
    name: string;
}
export interface Entity1IdView extends IdView<string> {
}
export interface IdView<T extends Serializable> {  // added generic bound
    id: T;
}
export interface Serializable {
}

I think it is needed to resolve generic variable T in Entity1View to string. Resolve generic variables is relatively complex in general case. I am thinking whether to use some library for it or implement it in typescript-generator.

This would be also useful for #219.

@olegshtch
Copy link
Contributor

It's strange but after rebase #389 on top master I get

interface Entity1View extends Entity1IdView {
    name: string;
}
interface Entity1IdView extends IdView<string> {
}
interface IdView<T extends string> {
    id: T;
}

from:

    public interface IdView<T extends String> {
        T getId();
    }

    public interface Entity1IdView extends IdView<String> {
    }

    public abstract class Entity1View implements Entity1IdView {
        private String name;

        public String getName() { return name; }
    }

It looks correct.

olegshtch pushed a commit to olegshtch/typescript-generator that referenced this issue Sep 3, 2019
@olegshtch
Copy link
Contributor

Looks like somehow it should generate class instead of interface to reproduce bug.

olegshtch pushed a commit to olegshtch/typescript-generator that referenced this issue Sep 3, 2019
@vojtechhabarta
Copy link
Owner

Fix released in version 2.17.558.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants