fix(compiler-cli): handle initializer APIs wrapped in type casts (#62203)

Fixes that the logic recognizing initializer APIs didn't account for the expression being wrapped in an `as` expresion or in a parenthesized expression. This was already accounted for in the diagnostic so these changes align the behavior between them.

Fixes #62197.

PR Close #62203
This commit is contained in:
Kristiyan Kostadinov 2025-06-23 09:13:01 +02:00
parent 223279eaf5
commit d25a6a0120
2 changed files with 38 additions and 0 deletions

View file

@ -82,6 +82,10 @@ export function tryParseInitializerApi<Functions extends InitializerApiFunction[
reflector: ReflectionHost,
importTracker: ImportedSymbolsTracker,
): (InitializerFunctionMetadata & {api: Functions[number]}) | null {
if (ts.isAsExpression(expression) || ts.isParenthesizedExpression(expression)) {
return tryParseInitializerApi(functions, expression.expression, reflector, importTracker);
}
if (!ts.isCallExpression(expression)) {
return null;
}

View file

@ -433,5 +433,39 @@ runInEachFileSystem(() => {
expect(diagnostics.length).toBe(0);
});
});
it('should resolve input inside an `as` expression', () => {
env.write(
'test.ts',
`
import {Directive, input, Signal} from '@angular/core';
@Directive()
export class TestDir {
data = input('test') as Signal<string>;
}
`,
);
env.driveMain();
const js = env.getContents('test.js');
expect(js).toContain('inputs: { data: [1, "data"] }');
});
it('should resolve input inside a parenthesized expression', () => {
env.write(
'test.ts',
`
import {Directive, input, Signal} from '@angular/core';
@Directive()
export class TestDir {
data = ((input('test')));
}
`,
);
env.driveMain();
const js = env.getContents('test.js');
expect(js).toContain('inputs: { data: [1, "data"] }');
});
});
});