Ability to create class definition instead of interface

Issue #66 new
Kevin Bennett
created an issue

Perhaps this is already possible, but did not see any obvious way to do it

Comments (6)

  1. Scott Gines

    I just ran into this same issue today. I changed the TsGenerator.cs file as was suggested in the SO thread. However, these are simply DTO's and don't have any logic associated with them at all.

    It would be nice if this were somehow changeable on the .tt template.

  2. Neil Barnwell

    You don't have to write an implementation. Because it's javascript, if you have a TypeScript interface like

    interface MyDto { name: string }
    

    then wherever there's a property or function that takes that type for one of it's arguments argument, you only have to pass something that's the same "shape". So you can do

    obj.DoSomethingWith({ name = "Eric" });
    

    Apologies if I've messed up the syntax slightly, I typed straight into the comment box. I'd still like the feature, just wanted to point out there is a workaround. If you want to "new-up" an object, you still don't need an impl, because you can do this:

    let obj: MyDto = {
       name: "Eric"
    };
    

    You'll get "compiler" warnings if you add a property to MyDto and don't go around adding it where required, though. It's a bit like a ctor in that sense.

  3. Log in to comment