Skip to content

Commit c085c97

Browse files
authored
Merge pull request #22 from huan086/inheritance-hierarchy
Emit class and interface that inherits, even when the body is empty.
2 parents 239b3a2 + e660771 commit c085c97

File tree

8 files changed

+79
-5
lines changed

8 files changed

+79
-5
lines changed

spec/FileEmitterSpec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ describe("UseCases", function () {
6363
runCase("Enum");
6464
runCase("Property");
6565
runCase("Class");
66-
66+
runCase("Interface");
67+
6768
runCase("AspNetCoreControllerToAngularClient", () => {
6869
var controllerClassFilter = (classObject: CSharpClass) => {
6970
var isTypeController = (type: {name: string}) => type.name.endsWith("Controller");

spec/cases/Class.case.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,13 @@ public class SubClass
2828
class OtherClass
2929
{
3030
public string MyProperty { get; set; }
31-
}
31+
}
32+
33+
class BaseGenericClass<T>
34+
{
35+
public T MyProperty { get; set; }
36+
}
37+
38+
class ConcreteTypeClass : BaseGenericClass<long>
39+
{
40+
}

spec/cases/Class.expected.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,11 @@ declare namespace MainClass {
2020

2121
declare interface OtherClass {
2222
myProperty: string;
23+
}
24+
25+
declare interface BaseGenericClass<T> {
26+
myProperty: T;
27+
}
28+
29+
declare interface ConcreteTypeClass extends BaseGenericClass<number> {
2330
}

spec/cases/Interface.case.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
interface IBefore
2+
{
3+
string MyProperty { get; set; }
4+
5+
void MyMethod(string foo, params string[] bar);
6+
7+
void MyNullParameterMethod(string foo = null);
8+
9+
Task<IEnumerable<string>> TaskArrayMethod();
10+
}
11+
12+
interface IMain<Foo> where Foo : new()
13+
{
14+
string MyProperty { get; set; }
15+
16+
SomeStuff<OtherStuff, RegularStuff> BlahProperty { get; set; }
17+
18+
List<OtherStuff> OtherBlahProperty { get; set; }
19+
}
20+
21+
interface IOther
22+
{
23+
string MyProperty { get; set; }
24+
}
25+
26+
interface IGeneric<T>
27+
{
28+
T MyProperty { get; set; }
29+
}
30+
31+
interface IConcreteType : IGeneric<long>
32+
{
33+
}

spec/cases/Interface.expected.d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
declare interface IBefore {
2+
myProperty: string;
3+
myMethod(foo: string, ...bar: Array<string>): void;
4+
myNullParameterMethod(foo?: string): void;
5+
taskArrayMethod(): Promise<Array<string>>;
6+
}
7+
8+
declare interface IMain<Foo> {
9+
myProperty: string;
10+
blahProperty: SomeStuff<OtherStuff, RegularStuff>;
11+
otherBlahProperty: Array<OtherStuff>;
12+
}
13+
14+
declare interface IOther {
15+
myProperty: string;
16+
}
17+
18+
declare interface IGeneric<T> {
19+
myProperty: T;
20+
}
21+
22+
declare interface IConcreteType extends IGeneric<number> {
23+
}

src/ClassEmitter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ export class ClassEmitter {
9999
var hasDirectChildren =
100100
classObject.properties.length > 0 ||
101101
classObject.methods.length > 0 ||
102-
classObject.fields.length > 0;
102+
classObject.fields.length > 0 ||
103+
classObject.inheritsFrom.length > 0;
103104

104105
if (!hasDirectChildren && !hasNestedChildren) {
105106
this.logger.log("Skipping emitting body of class " + classObject.name + " because it contains no children");

src/InterfaceEmitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class InterfaceEmitter {
7777
if (!options.filter(interfaceObject))
7878
return [];
7979

80-
if (interfaceObject.properties.length === 0 && interfaceObject.methods.length === 0) {
80+
if (interfaceObject.properties.length === 0 && interfaceObject.methods.length === 0 && interfaceObject.implements.length === 0) {
8181
this.logger.log("Skipping emitting body of interface " + interfaceObject.name + " because it contains no properties or methods");
8282
return [];
8383
}

src/TypeEmitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class TypeEmitter {
7070
var typeName = this.getNonGenericMatchingTypeMappingAsString(type, options);
7171
return ts.createExpressionWithTypeArguments(
7272
this.createTypeScriptTypeReferenceNodes(
73-
type.genericParameters,
73+
type.genericParameters.map(p => this.getMatchingTypeMappingAsType(p, options)),
7474
options),
7575
ts.createIdentifier(typeName));
7676
}

0 commit comments

Comments
 (0)