diff --git a/packages/compiler-cli/src/ngtsc/typecheck/src/type_check_block.ts b/packages/compiler-cli/src/ngtsc/typecheck/src/type_check_block.ts index 34ceffb1f0..cb568f9911 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/src/type_check_block.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/src/type_check_block.ts @@ -122,7 +122,7 @@ class TcbVariableOp extends TcbOp { const id = this.tcb.allocateId(); const initializer = ts.createPropertyAccess( /* expression */ ctx, - /* name */ this.variable.value); + /* name */ this.variable.value || '$implicit'); // Declare the variable, and return its identifier. this.scope.addStatement(tsCreateVariable(id, initializer)); diff --git a/packages/compiler-cli/src/ngtsc/typecheck/test/type_check_block_spec.ts b/packages/compiler-cli/src/ngtsc/typecheck/test/type_check_block_spec.ts index e17e4f1a02..d215831881 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/test/type_check_block_spec.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/test/type_check_block_spec.ts @@ -45,6 +45,16 @@ describe('type check blocks', () => { expect(tcb(TEMPLATE)).toContain('_t1.htmlFor = "test";'); }); + it('should handle implicit vars on ng-template', () => { + const TEMPLATE = ``; + expect(tcb(TEMPLATE)).toContain('var _t2 = _t1.$implicit;'); + }); + + it('should handle implicit vars when using microsyntax', () => { + const TEMPLATE = `
`; + expect(tcb(TEMPLATE)).toContain('var _t2 = _t1.$implicit;'); + }); + it('should generate a forward element reference correctly', () => { const TEMPLATE = ` {{ i.value }}