File tree Expand file tree Collapse file tree 2 files changed +30
-4
lines changed
packages/core/schematics/migrations/output-migration Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,28 @@ describe('outputs', () => {
33
33
} ) ;
34
34
} ) ;
35
35
36
+ it ( 'should keep type without initializer' , async ( ) => {
37
+ await verifyDeclaration ( {
38
+ before : '@Output() eventMovement: EventEmitter<IResponse> = new EventEmitter();' ,
39
+ after : 'readonly eventMovement = output<IResponse>();' ,
40
+ } ) ;
41
+ } ) ;
42
+
43
+ it ( 'should keep type with initializer' , async ( ) => {
44
+ await verifyDeclaration ( {
45
+ before : '@Output() eventMovement: EventEmitter = new EventEmitter<IResponse>();' ,
46
+ after : 'readonly eventMovement = output<IResponse>();' ,
47
+ } ) ;
48
+ } ) ;
49
+
50
+ it ( 'should keep type without initializer and with alias' , async ( ) => {
51
+ await verifyDeclaration ( {
52
+ before :
53
+ "@Output('customEvent') eventMovement: EventEmitter<IResponse> = new EventEmitter();" ,
54
+ after : "readonly eventMovement = output<IResponse>({ alias: 'customEvent' });" ,
55
+ } ) ;
56
+ } ) ;
57
+
36
58
it ( 'should migrate declaration without type hint' , async ( ) => {
37
59
await verifyDeclaration ( {
38
60
before : '@Output() readonly someChange = new EventEmitter();' ,
Original file line number Diff line number Diff line change @@ -28,10 +28,14 @@ export function calculateDeclarationReplacement(
28
28
aliasParam ?: string ,
29
29
) : Replacement {
30
30
const sf = node . getSourceFile ( ) ;
31
- const payloadTypes =
32
- node . initializer !== undefined && ts . isNewExpression ( node . initializer )
33
- ? node . initializer ?. typeArguments
34
- : undefined ;
31
+
32
+ let payloadTypes : ts . NodeArray < ts . TypeNode > | undefined ;
33
+
34
+ if ( node . initializer && ts . isNewExpression ( node . initializer ) && node . initializer . typeArguments ) {
35
+ payloadTypes = node . initializer . typeArguments ;
36
+ } else if ( node . type && ts . isTypeReferenceNode ( node . type ) && node . type . typeArguments ) {
37
+ payloadTypes = ts . factory . createNodeArray ( node . type . typeArguments ) ;
38
+ }
35
39
36
40
const outputCall = ts . factory . createCallExpression (
37
41
ts . factory . createIdentifier ( 'output' ) ,
You can’t perform that action at this time.
0 commit comments