Repository navigation
Description
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
An error occurs in HTML when using an interface (object) with option keys.
app.component.ts
import { Component } from '@angular/core';
export interface MyInterface {
one?: string;
two?: string;
three?: string;
}
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent {
myData: MyInterface = {
one: 'One',
two: 'Two',
};
}app.component.html
<ng-container *ngFor="let entry of myData | keyvalue">
<div>{{ entry.key }}: {{ entry.value }}</div>
</ng-container>VSCode with Angular Language Service

No error when using serve but on build (prod). The VSCode extension Angular Language Service also shows this error in HTML. Never seen before. So I'm not 100% if this is a regression. But maybe I never worked with interface with an optional key here. Anyway, the code works during runtime. It seems to be a type interference. We need to allow optional keys (undefined).
Please provide a link to a minimal reproduction of the bug
Please provide the exception or error you saw
No overload matches this call.
The last overload gave the following error.
Argument of type 'MyInterface' is not assignable to parameter of type 'Record<keyof MyInterface, string> | ReadonlyMap<keyof MyInterface, string>'.ngtsc(2769)
Please provide the environment you discovered this bug in (run ng version)
Angular CLI: 13.3.8
Node: 14.19.0
Package Manager: npm 6.14.16
OS: win32 x64
Angular: 13.3.11
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1202.15
@angular-devkit/build-angular 13.3.8
@angular-devkit/core 12.2.15
@angular-devkit/schematics 12.2.15
@angular/cli 13.3.8
@schematics/angular 12.2.15
rxjs 6.6.7
typescript 4.6.4
Anything else?
I tested this in the latest Angular 12, 13 and 14. I see no error on StackBlitz (no Language Service ext.) and the code works well during runtime.
The error disappears when allow additional keys like this:
export interface MyInterface {
one?: string;
two?: string;
three?: string;
[key: string]: string;
}Or casting to any. But these is just ugly and against clean or professional code.
Activity
Quentame commentedon Nov 22, 2022
Hello !
Having the same issue on Angular 14.2.
Here is a minimalist reproduction of the issue☺️
Reproduction of the bug
Template (not changed during reproduction steps)
Component (not changed during reproduction steps)
Case 1: interface, no optionals
--> ✔️ working
Case 2: interface, optionals
--> ❌ template error
No overload matches this call. The last overload gave the following error. Argument of type 'KeyPipeIssueTestObjectMetadata' is not assignable to parameter of type 'Record<"thing", string | undefined> | ReadonlyMap<"thing", string | undefined> | null | undefined'.ngtsc(2769)Case 3: no interface, optionals
--> ✔️ working ... ???
Case 4: no interface, no optionals
--> ✔️ working ... of course 😄
Case 5: interface, optionals with additional keys
--> ✔️ working
Hope that helps !
VrushaliRThorat commentedon Dec 14, 2022
*** AppComponent ***
export class AppComponent {
name = 'Angular';
myData: MyInterface = {
one: 'myOne',
two: 'mytwo',
};
}
export interface MyInterface {
one?: string;
two?: string;
three?: string;
[key: string]: string;
}
app.component.html
***Result ***
one ---> myOne
two ---> mytwo
Pipe with Optionala parameters work fine.
PaskalevStoyan commentedon May 11, 2023
@pkozlowski-opensource Hi there, I see that there is a PR opened for this issue and its approved, but the movement inside it went stale. Is there any update on this issue?
JeanMeche commentedon May 11, 2023
It still needs approvals from the Angular team !
feat(common): Support of optional keys for the KeyValue pipe
feat(common): Support of optional keys for the KeyValue pipe
feat(common): Support of optional keys for the KeyValue pipe
feat(common): Support of optional keys for the KeyValue pipe (angular…
feat(common): Support of optional keys for the KeyValue pipe
feat(common): Support of optional keys for the KeyValue pipe
feat(common): Support of optional keys for the KeyValue pipe
feat(common): Support of optional keys for the KeyValue pipe (#48814)
feat(common): Support of optional keys for the KeyValue pipe (angular…
feat(common): Support of optional keys for the KeyValue pipe (angular…
feat(common): Support of optional keys for the KeyValue pipe (angular…
feat(common): Support of optional keys for the KeyValue pipe (angular…
angular-automatic-lock-bot commentedon Nov 1, 2025
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.
feat(common): Support of optional keys for the KeyValue pipe (angular…