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

TypeScript interfaces should never reference classes #4932

Open
varganatt opened this issue Jul 4, 2024 · 0 comments
Open

TypeScript interfaces should never reference classes #4932

varganatt opened this issue Jul 4, 2024 · 0 comments

Comments

@varganatt
Copy link

NSwag.AspNetCore 14.0.8
Repo for reproduction: https://github.com/varganatt/NSwagRepro/blob/master/NSwagRepro.csproj
Settings: nswag.json

When you have a type that contains nested data, and generate both TypeScript classes and interfaces, the interfaces reference nested class data.

Interfaces should never reference generated classes.


I have an endpoint that returns nested data (NestedData.cs):

public class NestedData
{
    public InnerDetails Details => new();

    public class InnerDetails
    {
        public int SomeValue { get; set; }
    }
}

From the generated TypeScript code:

export class NestedData implements INestedData {
    // Implementation
}

export interface INestedData {
    details?: InnerDetails; // <--- THE PROBLEM
}

export class InnerDetails implements IInnerDetails {
    // Implementation
}

export interface IInnerDetails {
    someValue?: number;
}

INestedData.details should be specified as the type IInnerDetails, not InnerDetails.

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

No branches or pull requests

1 participant