Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions goldens/public-api/compiler-cli/compiler_options.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export interface TypeCheckingOptions {
strictInputAccessModifiers?: boolean;
strictInputTypes?: boolean;
strictLiteralTypes?: boolean;
strictNgTemplateTypes?: boolean;
Comment thread
JeanMeche marked this conversation as resolved.
Resolved
strictNullInputTypes?: boolean;
strictOutputEventTypes?: boolean;
strictSafeNavigationTypes?: boolean;
Expand Down
1 change: 1 addition & 0 deletions packages/compiler-cli/preprocessor/src/compiler_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export interface NgpCompilerOptions {
strictLiteralTypes?: boolean;
strictUnclaimedEventNames?: boolean;
strictUnknownElements?: boolean;
strictNgTemplateTypes?: boolean;
typeCheckHostBindings?: boolean;

// Diagnostics (`DiagnosticOptions`).
Expand Down
5 changes: 5 additions & 0 deletions packages/compiler-cli/preprocessor/src/tcb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export function buildTypeCheckingConfig(
allowDomEventAssertion: true,
checkUnclaimedEventNames: false,
checkUnknownElements: false,
checkTypeOfNgTemplateBindings: false,
};
} else {
typeCheckingConfig = {
Expand Down Expand Up @@ -264,6 +265,7 @@ export function buildTypeCheckingConfig(
allowDomEventAssertion: true,
checkUnclaimedEventNames: false,
checkUnknownElements: false,
checkTypeOfNgTemplateBindings: false,
};
}

Expand Down Expand Up @@ -305,6 +307,9 @@ export function buildTypeCheckingConfig(
if (options.strictUnknownElements !== undefined) {
typeCheckingConfig.checkUnknownElements = options.strictUnknownElements;
}
if (options.strictNgTemplateTypes !== undefined) {
typeCheckingConfig.checkTypeOfNgTemplateBindings = options.strictNgTemplateTypes;
}
typeCheckingConfig.typeCheckHostBindings = options.typeCheckHostBindings ?? true;
typeCheckingConfig.usePoisonedData =
usePoisonedData || Boolean(options._compilePoisonedComponents);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ export interface TypeCheckingOptions {
* Defaults to `false`.
*/
strictUnknownElements?: boolean;

/**
* Whether to check if unknown properties are bound to `<ng-template>`.
*
* If this is `true`, an error will be reported for unknown properties bound to an `<ng-template>`.
*
* Defaults to `false`.
*/
strictNgTemplateTypes?: boolean;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions packages/compiler-cli/src/ngtsc/core/src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,8 @@ export class NgCompiler {
this.options.extendedDiagnostics?.defaultCategory || DiagnosticCategoryLabel.Warning,
allowSignalsInTwoWayBindings,
allowDomEventAssertion,
checkTypeOfNgTemplateBindings: false, // 3p-only
// g3-only checkTypeOfNgTemplateBindings: true,
};
} else {
typeCheckingConfig = {
Expand Down Expand Up @@ -1164,6 +1166,8 @@ export class NgCompiler {
allowSignalsInTwoWayBindings,
allowDomEventAssertion,
checkUnknownElements: false,
checkTypeOfNgTemplateBindings: false, // 3p-only
// g3-only checkTypeOfNgTemplateBindings: true,
};
}

Expand Down Expand Up @@ -1205,6 +1209,9 @@ export class NgCompiler {
if (this.options.strictLiteralTypes !== undefined) {
typeCheckingConfig.strictLiteralTypes = this.options.strictLiteralTypes;
}
if (this.options.strictNgTemplateTypes !== undefined) {
typeCheckingConfig.checkTypeOfNgTemplateBindings = this.options.strictNgTemplateTypes;
}
if (
this.options.extendedDiagnostics?.checks?.controlFlowPreventingContentProjection !== undefined
) {
Expand Down
13 changes: 8 additions & 5 deletions packages/compiler-cli/src/ngtsc/typecheck/src/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,24 @@ export class RegistryDomSchemaChecker implements DomSchemaChecker<TemplateDiagno

const decorator = hostIsStandalone ? '@Component' : '@NgModule';
const schemas = `'${decorator}.schemas'`;
let errorMsg = `Can't bind to '${name}' since it isn't a known property of '${tagName}'.`;
if (tagName.startsWith('ng-')) {
const localTagName = tagName.startsWith(':')
? tagName.slice(tagName.indexOf(':', 1) + 1)
: tagName;
let errorMsg = `Can't bind to '${name}' since it isn't a known property of '${localTagName}'.`;
if (localTagName.startsWith('ng-')) {
errorMsg +=
`\n1. If '${name}' is an Angular directive, then add 'CommonModule' to the '${decorator}.imports' of this component.` +
`\n2. To allow any property add 'NO_ERRORS_SCHEMA' to the ${schemas} of this component.`;
} else if (tagName.indexOf('-') > -1) {
} else if (localTagName.indexOf('-') > -1) {
errorMsg +=
`\n1. If '${
tagName
localTagName
}' is an Angular component and it has '${name}' input, then verify that it is ${
hostIsStandalone
? "included in the '@Component.imports' of this component"
: 'part of this module'
}.` +
`\n2. If '${tagName}' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the ${schemas} of this component to suppress this message.` +
`\n2. If '${localTagName}' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the ${schemas} of this component to suppress this message.` +
`\n3. To allow any property add 'NO_ERRORS_SCHEMA' to the ${schemas} of this component.`;
}

Expand Down
1 change: 1 addition & 0 deletions packages/compiler-cli/src/ngtsc/typecheck/testing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export function tcb(
allowSignalsInTwoWayBindings: true,
allowDomEventAssertion: true,
checkUnknownElements: true,
checkTypeOfNgTemplateBindings: true,
...config,
};
options = options || {emitSpans: false};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export const ALL_ENABLED_CONFIG: Readonly<TypeCheckingConfig> = {
allowSignalsInTwoWayBindings: true,
allowDomEventAssertion: true,
checkUnknownElements: true,
checkTypeOfNgTemplateBindings: true,
};

// Remove 'ref' from TypeCheckableDirectiveMeta and add a 'selector' instead.
Expand Down
5 changes: 4 additions & 1 deletion packages/compiler-cli/test/ngtsc/template_mapping_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -800,13 +800,15 @@ runInEachFileSystem((os) => {
import {Component, Directive, Input, Output, EventEmitter, Pipe, NgModule} from '@angular/core';

@Directive({
selector: '[ngModel],[attr],[ngModelChange]',
selector: '[ngModel],[attr],[ngModelChange],[ngIf],[ngForOf]',
standalone: false,
})
export class AllDirective {
@Input() ngModel!: any;
@Output() ngModelChange = new EventEmitter<any>();
@Input() attr!: any;
@Input() ngIf!: any;
@Input() ngForOf!: any;
}

@Pipe({
Expand All @@ -826,6 +828,7 @@ runInEachFileSystem((os) => {
name = '';
isInitial = false;
doSomething() {}
showMessage() { return true; }
items: any[] = [];
greeting = '';
}
Expand Down
Loading
Loading