Angular keyvalue pipe gives wrong return type

Discussão em 'Angular' iniciado por imcoding, Dezembro 17, 2024.

  1. imcoding

    imcoding Guest

    I'm looking at this overload in the KeyValuePipe doc:

    @param input: Record<K, V> | ReadonlyMap<K, V>
    @param compareFn: ((a: KeyValue<K, V>, b: KeyValue<K, V>) => number) | null | undefined
    @returns KeyValue<K, V>[]


    My code:

    <mat-select [(ngModel)]="item.teamId">
    <mat-option *ngFor="let option of lookups.teams | keyvalue" [value]="option.key">
    {{ option.value }}
    </mat-option>
    </mat-select>


    lookups.teams has the type Record<number, string | undefined>. so I expected option to be KeyValue<number, string | undefined> according to the docs. However, it turns out to be KeyValue<string, string | undefined>

    I need option.key to be a number for ngModel to work. How can I fix it?

    Continue reading...

Compartilhe esta Página