@@ -17,6 +17,7 @@ function transform(input: string, additionalFiles?: Record<string, string>) {
17
17
return result ;
18
18
}
19
19
20
+ // tslint:disable-next-line: no-big-function
20
21
describe ( 'Constructor Parameter Transformer' , ( ) => {
21
22
it ( 'records class name in same module' , ( ) => {
22
23
const input = `
@@ -211,4 +212,40 @@ describe('Constructor Parameter Transformer', () => {
211
212
212
213
expect ( tags . oneLine `${ result } ` ) . toEqual ( tags . oneLine `${ output } ` ) ;
213
214
} ) ;
215
+
216
+ it ( 'should work with union type and nullable argument' , ( ) => {
217
+ const input = `
218
+ @Injectable()
219
+ export class ProvidedService {
220
+ constructor() { }
221
+ }
222
+
223
+ @Injectable()
224
+ export class LibService {
225
+ constructor(
226
+ @Optional() private service: ProvidedService | null,
227
+ ) {
228
+ }
229
+ }
230
+ ` ;
231
+
232
+ const output = `
233
+ import { __decorate, __param } from "tslib";
234
+
235
+ let ProvidedService = class ProvidedService { constructor() { } };
236
+ ProvidedService = __decorate([ Injectable() ], ProvidedService);
237
+ export { ProvidedService };
238
+
239
+ let LibService = class LibService {
240
+ constructor(service) { this.service = service; }
241
+ };
242
+ LibService.ctorParameters = () => [ { type: ProvidedService, decorators: [{ type: Optional }] } ];
243
+ LibService = __decorate([ Injectable(), __param(0, Optional()) ], LibService);
244
+ export { LibService };
245
+ ` ;
246
+
247
+ const result = transform ( input ) ;
248
+
249
+ expect ( tags . oneLine `${ result } ` ) . toEqual ( tags . oneLine `${ output } ` ) ;
250
+ } ) ;
214
251
} ) ;
0 commit comments