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', () => {
3333 } ) ;
3434 } ) ;
3535
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+
3658 it ( 'should migrate declaration without type hint' , async ( ) => {
3759 await verifyDeclaration ( {
3860 before : '@Output() readonly someChange = new EventEmitter();' ,
Original file line number Diff line number Diff line change @@ -28,10 +28,14 @@ export function calculateDeclarationReplacement(
2828 aliasParam ?: string ,
2929) : Replacement {
3030 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+ }
3539
3640 const outputCall = ts . factory . createCallExpression (
3741 ts . factory . createIdentifier ( 'output' ) ,
You can’t perform that action at this time.
0 commit comments