No announcement yet.

Generic Type Usage: Using Bridge.NET output from Typescript

  • Filter
  • Time
  • Show
Clear All
new posts

    Generic Type Usage: Using Bridge.NET output from Typescript

    Hello fellow Bridge.NETizens,

    I'm loving the framework, but am not sure I'm doing generics correctly or most simply (for use in Typescript). Using Typescript from Bridge.NET is seamless, my goal is to figure out how seamless I can make the reverse case.

    Here is a snippet of some of the generic classes I'm using (
    public class Property<T> : IProperty, IProperty<T>{
        public Property(T value){
            Value = value;
        public Property(){
            Value = default(T);
        public T Value {get;set;}
        public event Action Changed = delegate { };
        public event PropertyChangedEventHandler PropertyChanged = delegate { };
    As you can see in the Deck.NET js output, constructing a Property<string> in Javascript goes like this:
    var y = new (Property$1(System.String)).ctor();
    var x = new (Property$1(System.String)).$ctor1("Test");

    Utilizing the generated Typescript definition, I was finally able to get something to compile (albeit more verbose than the *.js):
    let y = new (SEL.Property$1<string>(Bridge.getType("")))();
    let x = new (SEL.Property$1<string>(Bridge.getType(""))).$ctor1("Test");
    I think I understand most of the inner-workings for the generated code. I'm not sure I understand he Bridge.getType("") portion being passed in for T$: Bridge.TypeRef<T> parameter.
    Is there no better way of accomplishing this? (i.e. in Javascript it is simply System.String -- which doesn't seem to work the same way in Typescript).
    Presumably there is no way to get the Bridge type object off of the Typescript <T>, but there must at least be a better way to access common types (and a pattern to to implement for class types)

    For example
    let y = new (SEL.Property$1<string>(Bridge.String))();
    let x = new (SEL.Property$1<string>(System.String.Type)).$ctor1("Test");
    Edit: I should note my version: * @version : 16.6.0 - Bridge.NET
    I noticed Deck.NET has version 16.6.1 -- Is there a way to get a hold of this newer release (I'm using Package Manager in VS, but would use any other install method for the new version)

    Edit2: The output files may have just not been updated? The extension said it was 16.6.1. I uninstalled and reinstalled anyway from the vsix file.


    When were generics introduced into Bridge.NET? Is it at all likely that generics (with one type param) will ever be syntactically simplified (i.e. is it even possible)?
    I really want to be able to go down the road of Bridge.NET -- But want the typescript API to be as simple as possible for third party integration (and it feels like I am simply missing something).
    Last edited by selinc; 2018-01-15 @ 03:25 PM.


      Hi selinc – Thanks for the reminder. We are reviewing today.


        "System.String" definition in bridge.d.ts has no "prototype" property. We will add it and after that, you should be able to use such code in typescript
         let y = new (SEL.Property$1(System.String))(); let x = new (SEL.Property$1<System.String>(System.String)).$ctor1("Test");
        "<System.String>" part is optional because compiler detects generic type from the argument.


          Thanks for the prompt response.

          I also managed to wrap this up for convience:

          class Property{
               static Create<T>(o: T): TestBridge.Property$1<T>{
                    let type: any = Bridge.getType(o);
                    return new (TestBridge.Property$1<T>(type)).$ctor1(o);
          Then this enables be to write to following:
          let x = Property.Create("Test");
          let z = Property.Create<TestObject>(new TestObject("")
          Is there someway to get this static factory into C#, such that a static factory method is generated js/Typescript (outputting the first chunk of code in this post)? Ideally this would be part of the same Property<T> class.

          I tried writing what I might expect to write, but didn't get the output I was looking for (type safe):
          This is what it generated (note the method has v as type any).
                          Create: function (v) {
                              return new (TestBridge.Property$1(T))(v);
          Last edited by selinc; 2018-01-15 @ 07:37 PM.