Si les genera el siguiente error para los metodos get de los servicios:
Type ‘Observable<{ key?: string | undefined; name?: string; country?: Country; players?: Player[]; $key: string | null; }[]>’ is not assignable to type ‘Observable<Team[]>’.
Type ‘{ key?: string | undefined; name?: string; country?: Country; players?: Player[]; $key: string | null; }[]’ is not assignable to type ‘Team[]’.
Type ‘{ key?: string | undefined; name?: string; country?: Country; players?: Player[]; $key: string | null; }’ is not assignable to type ‘Team’.
Property ‘name’ is optional in type ‘{ key?: string | undefined; name?: string; country?: Country; players?: Player[]; $key: string | null; }’ but required in type ‘Team’.
Para solucionarlo deben agregar ‘as Team’ (en este caso), si sucede con el servicio de Player agregar ‘as Player’ de la siguiente manera:
Player Service:
getPlayers(): Observable<Player[]> {
return this.playerDb.snapshotChanges().pipe(
map((changes) => {
return changes.map(
(c) =>
({
$key: c.payload.key,
...c.payload.val(),
} as Player)
);
})
);
}
Team Service:
getTeams(): Observable<Team[]> {
return this.teamDb.snapshotChanges().pipe(
map((changes) => {
return changes.map(
(c) =>
({
$key: c.payload.key,
...c.payload.val(),
} as Team)
);
})
);
}
Stack Overflow: https://stackoverflow.com/questions/54573563/type-key-string-is-not-assignable-to-type-product-angular-7/54592215#54592215
La solución la encontre gracias al usuario @silvana murgo más abajo en esta sección.
Los aportes, preguntas y respuestas son vitales para aprender en comunidad. Regístrate o inicia sesión para participar.