diff --git a/typescript-generator-core/src/main/java/cz/habarta/typescript/generator/compiler/ModelCompiler.java b/typescript-generator-core/src/main/java/cz/habarta/typescript/generator/compiler/ModelCompiler.java index ee77e0cf4..116d5b03f 100644 --- a/typescript-generator-core/src/main/java/cz/habarta/typescript/generator/compiler/ModelCompiler.java +++ b/typescript-generator-core/src/main/java/cz/habarta/typescript/generator/compiler/ModelCompiler.java @@ -151,7 +151,7 @@ private TsBeanModel processBean(SymbolTable symbolTable, Model model, Map properties, String private TsPropertyModel processProperty(SymbolTable symbolTable, BeanModel bean, PropertyModel property, String prefix, String suffix) { final TsType type = typeFromJava(symbolTable, property.getType(), property.getName(), bean.getOrigin()); final TsType tsType = property.isOptional() ? type.optional() : type; - return new TsPropertyModel(prefix + property.getName() + suffix, tsType, settings.declarePropertiesAsReadOnly, property.getComments()); + return new TsPropertyModel(prefix + property.getName() + suffix, tsType, settings.declarePropertiesAsReadOnly, false, property.getComments()); } private TsEnumModel processEnum(SymbolTable symbolTable, EnumModel enumModel) { @@ -238,7 +238,7 @@ private TsModel removeInheritedProperties(SymbolTable symbolTable, TsModel tsMod final Map inheritedPropertyTypes = getInheritedProperties(symbolTable, tsModel, bean.getParentAndInterfaces()); final List properties = new ArrayList<>(); for (TsPropertyModel property : bean.getProperties()) { - if (!Objects.equals(property.getTsType(), inheritedPropertyTypes.get(property.getName()))) { + if (property.isOwnProperty() || !Objects.equals(property.getTsType(), inheritedPropertyTypes.get(property.getName()))) { properties.add(property); } } diff --git a/typescript-generator-core/src/main/java/cz/habarta/typescript/generator/emitter/TsPropertyModel.java b/typescript-generator-core/src/main/java/cz/habarta/typescript/generator/emitter/TsPropertyModel.java index 4ee4e9e05..397b02000 100644 --- a/typescript-generator-core/src/main/java/cz/habarta/typescript/generator/emitter/TsPropertyModel.java +++ b/typescript-generator-core/src/main/java/cz/habarta/typescript/generator/emitter/TsPropertyModel.java @@ -9,12 +9,18 @@ public class TsPropertyModel extends TsProperty implements Comparable { public final boolean readonly; + public final boolean ownProperty; // property exists directly on the bean, should not be inherited public final List comments; - public TsPropertyModel(String name, TsType tsType, boolean readonly, List comments) { + public TsPropertyModel(String name, TsType tsType, boolean readonly, boolean ownProperty, List comments) { super(name, tsType); this.readonly = readonly; this.comments = comments; + this.ownProperty = ownProperty; + } + + public boolean isOwnProperty() { + return ownProperty; } public List getComments() { @@ -22,7 +28,7 @@ public List getComments() { } public TsPropertyModel setTsType(TsType type) { - return new TsPropertyModel(getName(), type, readonly, getComments()); + return new TsPropertyModel(getName(), type, readonly, ownProperty, getComments()); } @Override diff --git a/typescript-generator-core/src/test/java/cz/habarta/typescript/generator/GenericsTest.java b/typescript-generator-core/src/test/java/cz/habarta/typescript/generator/GenericsTest.java index b59468d80..f640486cb 100644 --- a/typescript-generator-core/src/test/java/cz/habarta/typescript/generator/GenericsTest.java +++ b/typescript-generator-core/src/test/java/cz/habarta/typescript/generator/GenericsTest.java @@ -84,6 +84,7 @@ public void testImplements() { final String nl = settings.newline; final String expected = "export interface IA extends IB {" + nl + + " type: string;" + nl + "}" + nl + "" + nl + "export interface IB {" + nl + diff --git a/typescript-generator-core/src/test/java/cz/habarta/typescript/generator/TaggedUnionsTest.java b/typescript-generator-core/src/test/java/cz/habarta/typescript/generator/TaggedUnionsTest.java index cf17bb8b7..24b77720b 100644 --- a/typescript-generator-core/src/test/java/cz/habarta/typescript/generator/TaggedUnionsTest.java +++ b/typescript-generator-core/src/test/java/cz/habarta/typescript/generator/TaggedUnionsTest.java @@ -196,7 +196,6 @@ public void testTaggedUnionsWithInterfaces() { public void testTaggedUnionsWithOverlappingInterfaces() { final Settings settings = TestUtils.settings(); final String output = new TypeScriptGenerator(settings).generateTypeScript(Input.from(IShape3.class)); - System.out.println(output); final String expected = ( "\n" + "interface IShape3 {\n" + @@ -204,6 +203,7 @@ public void testTaggedUnionsWithOverlappingInterfaces() { "}\n" + "\n" + "interface IRectangle3 extends INamedQuadrilateral3 {\n" + + " kind: 'rectangle';\n" + "}\n" + "\n" + "interface ICircle3 extends INamedShape3 {\n" + @@ -215,6 +215,7 @@ public void testTaggedUnionsWithOverlappingInterfaces() { "}\n" + "\n" + "interface INamedShape3 extends IShape3 {\n" + + " kind: 'circle' | 'rectangle';\n" + " name: string;\n" + "}\n" + "\n" + @@ -266,7 +267,6 @@ public void testTaggedUnionsDisabled() { public void testTaggedUnionsWithDiamond() { final Settings settings = TestUtils.settings(); final String output = new TypeScriptGenerator(settings).generateTypeScript(Input.from(DiamondA.class)); - System.out.println(output); final String expected = ( "\n" + "interface DiamondA {\n" +