Ejemplo n.º 1
0
        public void Simple()
        {
            var tsInterface = new TsInterface
            {
                ExportKind = TsExportKind.Named,
                Name       = "SomeInterface",
                Properties = new[]
                {
                    new TsPropertySignature {
                        Name = "FirstProperty", Type = TsPredefinedType.Boolean()
                    },
                    new TsPropertySignature {
                        Name = "SecondProperty", Type = TsPredefinedType.Number(), Optional = true
                    },
                    new TsPropertySignature {
                        Name = "ThirdProperty", Type = new TsUnionType(TsPredefinedType.String(), new TsNull())
                    },
                    new TsPropertySignature {
                        Name = "FourthProperty", Type = new TsArrayType {
                            ElementType = new TsUnionType(TsPredefinedType.String(), new TsNull())
                        }
                    }
                }
            };

            tsInterface.ShouldBeTranslatedTo("export interface SomeInterface {",
                                             "    FirstProperty: boolean;",
                                             "    SecondProperty?: number;",
                                             "    ThirdProperty: (string | null);",
                                             "    FourthProperty: (string | null)[];",
                                             "}");
        }
Ejemplo n.º 2
0
 public static TsIndexSignature ByString(TsType valueType)
 {
     return(new TsIndexSignature
     {
         IndexType = TsPredefinedType.String(),
         ValueType = valueType
     });
 }
Ejemplo n.º 3
0
 public static TsIndexSignature ByNumber(TsType valueType)
 {
     return(new TsIndexSignature
     {
         IndexType = TsPredefinedType.Number(),
         ValueType = valueType
     });
 }