Public readonly fields

Issue #19 new
Pavel Martynov
created an issue

Please, support public readonly fields. My code full of immutable classes which I want to serialize as json and send to client. Example:

class Person { public readonly string FirstName; public readonly string LastName; public readonly int Age;

public Person(string firstName, string lastName, int age)
    FirstName = firstName;
    LastName = lastName;
    Age = age;


Result: interface Person { }

Comments (3)

  1. Lukas Kabrt repo owner

    I am not aware of a way to express readonly field in t.ds file. IMHO the only viable option is to treat fields and readonly fields the same way as properties. I am not sure whether this wouldn't be confusing ...

  2. Johnny Depp

    I know this issue is already 3 years old. But this feature would be really nice. It would be enough for me (and I guess for other users too) if the public readonly fields are generates the same way as properties.

    Right now I'm using the workaround with getter only properties. These are working, even tough the generates interface in TypeScript would also be incorrect, because it allows to set the value. If you're afraid of breaking changes, the feature could be deactivated by default and need explicit activating.

    I'd create a pull request, if you're considering to integrate the feature.

  3. Lukas Kabrt repo owner

    I know, that this is quite popular request. Unfortunately I don’t have enough time to implement it myself, but if you create a pull request I will be happy to integrate it to the library.

  4. Log in to comment