File tree Expand file tree Collapse file tree 5 files changed +23
-1
lines changed
packages/compiler-cli/src/ngtsc Expand file tree Collapse file tree 5 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -1057,6 +1057,9 @@ export class NgCompiler {
10571057 const allowSignalsInTwoWayBindings =
10581058 this . angularCoreVersion === null ||
10591059 coreVersionSupportsFeature ( this . angularCoreVersion , '>= 17.2.0-0' ) ;
1060+ const allowDomEventAssertion =
1061+ this . angularCoreVersion === null ||
1062+ coreVersionSupportsFeature ( this . angularCoreVersion , '>= 20.2.0' ) ;
10601063
10611064 // First select a type-checking configuration, based on whether full template type-checking is
10621065 // requested.
@@ -1101,6 +1104,7 @@ export class NgCompiler {
11011104 this . options . extendedDiagnostics ?. defaultCategory || DiagnosticCategoryLabel . Warning ,
11021105 allowSignalsInTwoWayBindings,
11031106 checkTwoWayBoundEvents,
1107+ allowDomEventAssertion,
11041108 } ;
11051109 } else {
11061110 typeCheckingConfig = {
@@ -1136,6 +1140,7 @@ export class NgCompiler {
11361140 this . options . extendedDiagnostics ?. defaultCategory || DiagnosticCategoryLabel . Warning ,
11371141 allowSignalsInTwoWayBindings,
11381142 checkTwoWayBoundEvents,
1143+ allowDomEventAssertion,
11391144 } ;
11401145 }
11411146
Original file line number Diff line number Diff line change @@ -353,6 +353,11 @@ export interface TypeCheckingConfig {
353353 */
354354 allowSignalsInTwoWayBindings : boolean ;
355355
356+ /**
357+ * Whether the type of DOM events should be asserted with '@angular/core' 'ɵassertType' (see TCB implementation).
358+ */
359+ allowDomEventAssertion : boolean ;
360+
356361 /**
357362 * Whether to descend into the bodies of control flow blocks (`@if`, `@switch` and `@for`).
358363 */
Original file line number Diff line number Diff line change @@ -1680,7 +1680,8 @@ class TcbUnclaimedOutputsOp extends TcbOp {
16801680 if (
16811681 this . target instanceof TmplAstElement &&
16821682 this . target . isVoid &&
1683- ts . isIdentifier ( target )
1683+ ts . isIdentifier ( target ) &&
1684+ this . tcb . env . config . allowDomEventAssertion
16841685 ) {
16851686 domEventAssertion = ts . factory . createCallExpression (
16861687 this . tcb . env . referenceExternalSymbol ( '@angular/core' , 'ɵassertType' ) ,
Original file line number Diff line number Diff line change @@ -1077,6 +1077,7 @@ describe('type check blocks', () => {
10771077 unusedStandaloneImports : 'warning' ,
10781078 allowSignalsInTwoWayBindings : true ,
10791079 checkTwoWayBoundEvents : true ,
1080+ allowDomEventAssertion : true ,
10801081 } ;
10811082
10821083 describe ( 'config.applyTemplateContextGuards' , ( ) => {
@@ -1455,6 +1456,14 @@ describe('type check blocks', () => {
14551456 } ) ;
14561457 } ) ;
14571458
1459+ it ( 'should _not_ assert the type for DOM events bound on void elements when disabled' , ( ) => {
1460+ const result = tcb ( `<input (input)="handleInput($event.target.value)">` , undefined , {
1461+ ...BASE_CONFIG ,
1462+ allowDomEventAssertion : false ,
1463+ } ) ;
1464+ expect ( result ) . not . toContain ( 'ɵassertType' ) ;
1465+ } ) ;
1466+
14581467 describe ( 'config.allowSignalsInTwoWayBindings' , ( ) => {
14591468 it ( 'should not unwrap signals in two-way binding expressions' , ( ) => {
14601469 const TEMPLATE = `<div twoWay [(input)]="value"></div>` ;
Original file line number Diff line number Diff line change @@ -291,6 +291,7 @@ export const ALL_ENABLED_CONFIG: Readonly<TypeCheckingConfig> = {
291291 unusedStandaloneImports : 'warning' ,
292292 allowSignalsInTwoWayBindings : true ,
293293 checkTwoWayBoundEvents : true ,
294+ allowDomEventAssertion : true ,
294295} ;
295296
296297// Remove 'ref' from TypeCheckableDirectiveMeta and add a 'selector' instead.
@@ -433,6 +434,7 @@ export function tcb(
433434 suggestionsForSuboptimalTypeInference : false ,
434435 allowSignalsInTwoWayBindings : true ,
435436 checkTwoWayBoundEvents : true ,
437+ allowDomEventAssertion : true ,
436438 ...config ,
437439 } ;
438440 options = options || { emitSpans : false } ;
You can’t perform that action at this time.
0 commit comments