mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(core): fix ng generate @angular/core:output-migration (#60626)
output-migration command not keep type if @output declaring without initializer PR Close #60626
This commit is contained in:
committed by
Jessica Janiuk
parent
4546d4fb39
commit
cdbc6e8ec1
@@ -33,6 +33,28 @@ describe('outputs', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should keep type without initializer', async () => {
|
||||
await verifyDeclaration({
|
||||
before: '@Output() eventMovement: EventEmitter<IResponse> = new EventEmitter();',
|
||||
after: 'readonly eventMovement = output<IResponse>();',
|
||||
});
|
||||
});
|
||||
|
||||
it('should keep type with initializer', async () => {
|
||||
await verifyDeclaration({
|
||||
before: '@Output() eventMovement: EventEmitter = new EventEmitter<IResponse>();',
|
||||
after: 'readonly eventMovement = output<IResponse>();',
|
||||
});
|
||||
});
|
||||
|
||||
it('should keep type without initializer and with alias', async () => {
|
||||
await verifyDeclaration({
|
||||
before:
|
||||
"@Output('customEvent') eventMovement: EventEmitter<IResponse> = new EventEmitter();",
|
||||
after: "readonly eventMovement = output<IResponse>({ alias: 'customEvent' });",
|
||||
});
|
||||
});
|
||||
|
||||
it('should migrate declaration without type hint', async () => {
|
||||
await verifyDeclaration({
|
||||
before: '@Output() readonly someChange = new EventEmitter();',
|
||||
|
||||
@@ -28,10 +28,14 @@ export function calculateDeclarationReplacement(
|
||||
aliasParam?: string,
|
||||
): Replacement {
|
||||
const sf = node.getSourceFile();
|
||||
const payloadTypes =
|
||||
node.initializer !== undefined && ts.isNewExpression(node.initializer)
|
||||
? node.initializer?.typeArguments
|
||||
: undefined;
|
||||
|
||||
let payloadTypes: ts.NodeArray<ts.TypeNode> | undefined;
|
||||
|
||||
if (node.initializer && ts.isNewExpression(node.initializer) && node.initializer.typeArguments) {
|
||||
payloadTypes = node.initializer.typeArguments;
|
||||
} else if (node.type && ts.isTypeReferenceNode(node.type) && node.type.typeArguments) {
|
||||
payloadTypes = ts.factory.createNodeArray(node.type.typeArguments);
|
||||
}
|
||||
|
||||
const outputCall = ts.factory.createCallExpression(
|
||||
ts.factory.createIdentifier('output'),
|
||||
|
||||
Reference in New Issue
Block a user