jburzynski / TypeGen

Single-class-per-file C# to TypeScript generator
MIT License
195 stars 55 forks source link

Static members should always be ignored when generating interfaces #192

Open DaRosenberg opened 7 months ago

DaRosenberg commented 7 months ago

Currently, given this C# class:

public class NormalizationCounts
{
    public static readonly NormalizationCounts Zero = new(0, 0);
    public static readonly NormalizationCounts Success = new(1, 0);
    public static readonly NormalizationCounts Failure = new(0, 1);

    private NormalizationCounts(int numberComponentsNormalized, int numberComponentsFailed)
    {
        NumberComponentsNormalized = numberComponentsNormalized;
        NumberComponentsFailed = numberComponentsFailed;
    }

    public int NumberComponentsNormalized { get; }
    public int NumberComponentsFailed { get; }
}

TypeGen generates the following TypeScript interface:

export interface NormalizationCounts {
    readonly zero: NormalizationCounts;
    readonly success: NormalizationCounts;
    readonly failure: NormalizationCounts;
    numberComponentsNormalized: number;
    numberComponentsFailed: number;
}

It might make sense to include static members when generating classes, but when generating interfaces then IMO this makes absolutely zero sense.

I would suggest to either ignore static members by default when generating interfaces, or at the very least add a global configuration option to do so.