Skip to content

Commit 16fe27b

Browse files
tmplnleonsenft
authored andcommitted
fix(core): do not insert todo when migrating void @output
The following: `@Output() someChange = new EventEmitter<void>();` is correctly migrated to: `readonly someChange = output<void>();` However, a TODO is incorrectly inserted for subsequent emissions from `someChange`, stating that an argument is expected.
1 parent 49ccb51 commit 16fe27b

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

packages/core/schematics/migrations/output-migration/output-migration.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,35 @@ describe('outputs', () => {
198198
});
199199
});
200200

201+
it('should not insert a TODO comment for emit function with void type', async () => {
202+
await verify({
203+
before: `
204+
import {Directive, Output, EventEmitter} from '@angular/core';
205+
206+
@Directive()
207+
export class TestDir {
208+
@Output() someChange = new EventEmitter<void>();
209+
210+
someMethod(): void {
211+
this.someChange.emit();
212+
}
213+
}
214+
`,
215+
after: `
216+
import {Directive, output} from '@angular/core';
217+
218+
@Directive()
219+
export class TestDir {
220+
readonly someChange = output<void>();
221+
222+
someMethod(): void {
223+
this.someChange.emit();
224+
}
225+
}
226+
`,
227+
});
228+
});
229+
201230
it('should insert a TODO comment for emit function with type', async () => {
202231
await verify({
203232
before: `

packages/core/schematics/migrations/output-migration/output-migration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ function addCommentForEmptyEmit(
477477
if (!propertyDeclaration) return;
478478

479479
const eventEmitterType = getEventEmitterArgumentType(propertyDeclaration);
480-
if (!eventEmitterType) return;
480+
if (!eventEmitterType || eventEmitterType === 'void') return;
481481

482482
const id = getUniqueIdForProperty(info, propertyDeclaration);
483483
const file = projectFile(node.getSourceFile(), info);

0 commit comments

Comments
 (0)