question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dto with interfaces has no implements

See original GitHub issue

So, here’s an example:

    public interface ICard
    {
         string Title { get; set; }
         string Description { get; set;
    }

Which has a final DTO of this form:

    public class Card : ICard
    {
         string Title { get; set; }
         string Description { get; set;
    }

The final output using typegen is:

/**
 * This is a TypeGen auto-generated file.
 * Any changes made to this file can be lost when this file is regenerated.
 */

export class ICard {
    title: string;
    description: string;
}
/**
 * This is a TypeGen auto-generated file.
 * Any changes made to this file can be lost when this file is regenerated.
 */

export class Card {
    title: string;
    description: string;
}

I was expected to have this instead:

/**
 * This is a TypeGen auto-generated file.
 * Any changes made to this file can be lost when this file is regenerated.
 */

import { ICard} from "./i-card";

export class Card implements ICard {
    title: string;
    description: string;
}

Is there any way to achieve this right now?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Allovcommented, Feb 27, 2020

Can confirm, only supporting extends: https://github.com/jburzynski/TypeGen/blob/master/src/TypeGen/TypeGen.Core/Templates/Class.tpl

I’m working on a PR, just need to figure out imports.

1reaction
taylorjpcommented, Feb 28, 2020

I’m running into this issue as well with inherited interfaces. I want to pass around the lowest level interface in typescript, but I can’t because it actually doesn’t have all the properties.

Example C# interfaces:

public interface IAggregateDto : ICalculationDto
{
    int AggregationType { get; set; }
}

public interface ICalculationDto
{
    string name { get; set; }
}

and the generated Typescript code:

export interface IAggregateDto {
    int AggregationType: number;
}

export interface ICalculationDto {
    name: string;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Should I create interfaces for data transfer objects?
The general answer is no, because you should never add code without having a specific, concrete reason for it, and there is no...
Read more >
How to handle Dtos for objects which implement multiple ...
Using interfaces in the service is not recommended and is the cause of the problem, as when you try and substitute concrete classes...
Read more >
Avoiding interfaces in DTOs
I am trying to get my head around the best DTO design for a particular use case. Our application supports custom properties which...
Read more >
Immutable DTOs in C# with interfaces
Upside is that the project won't even build if the updated interface isn't implemented. On other hand, the alternative to reusing the same...
Read more >
I've seen implemented contracts/interfaces for simple DTO ...
I do not believe that interfaces (C#/Java) are contracts. They mandate implementation of the interface but cannot guarantee the behaviour of the implementation....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found