Skip to content

Commit 32c849d

Browse files
committed
Added another test for type parameters with constraints
1 parent 41ac351 commit 32c849d

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

test/json/declarations/class_test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,34 @@ describe('classes', () => {
191191
}
192192
]
193193
}));
194+
195+
expectTranslateJSON('declare class X<U extends number, T extends Promise<U>> {}')
196+
.to.equal(prettyStringify({
197+
kind: ConvertedSyntaxKind.SourceFile,
198+
fileName: 'demo/some/main.ts',
199+
statements: [{
200+
kind: ConvertedSyntaxKind.ClassDeclaration,
201+
modifiers: [],
202+
name: 'X',
203+
typeParameters: [
204+
{
205+
kind: ConvertedSyntaxKind.TypeParameter,
206+
name: 'U',
207+
constraint: {kind: ConvertedSyntaxKind.KeywordType, typeName: 'number'}
208+
},
209+
{
210+
kind: ConvertedSyntaxKind.TypeParameter,
211+
name: 'T',
212+
constraint: {
213+
kind: ConvertedSyntaxKind.TypeReference,
214+
typeName: 'Promise',
215+
typeArguments: [{kind: ConvertedSyntaxKind.TypeReference, typeName: 'U'}]
216+
}
217+
}
218+
],
219+
members: []
220+
}]
221+
}));
194222
});
195223
});
196224

test/json/declarations/interface_test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,34 @@ describe('interfaces', () => {
116116
}
117117
]
118118
}));
119+
120+
expectTranslateJSON('declare interface X<U extends number, T extends Promise<U>> {}')
121+
.to.equal(prettyStringify({
122+
kind: ConvertedSyntaxKind.SourceFile,
123+
fileName: 'demo/some/main.ts',
124+
statements: [{
125+
kind: ConvertedSyntaxKind.InterfaceDeclaration,
126+
modifiers: [],
127+
name: 'X',
128+
typeParameters: [
129+
{
130+
kind: ConvertedSyntaxKind.TypeParameter,
131+
name: 'U',
132+
constraint: {kind: ConvertedSyntaxKind.KeywordType, typeName: 'number'}
133+
},
134+
{
135+
kind: ConvertedSyntaxKind.TypeParameter,
136+
name: 'T',
137+
constraint: {
138+
kind: ConvertedSyntaxKind.TypeReference,
139+
typeName: 'Promise',
140+
typeArguments: [{kind: ConvertedSyntaxKind.TypeReference, typeName: 'U'}]
141+
}
142+
}
143+
],
144+
members: []
145+
}]
146+
}));
119147
});
120148
});
121149

0 commit comments

Comments
 (0)