¿Cómo resolver el error de Angular con la tubería asíncrona?
Actualmente estoy experimentando un problema con Angular, si utilizo varios pipes además del pipe async así:
Mis à jour : {{ lastUpdate | async | date: 'yMMMMEEEEd' | uppercase }}
el código no se puede compilar y tengo este error:
Error: src/app/app.component.html:5:39 – error TS2769: No overload matches this call.
Overload 1 of 3, ‘(value: string | number | Date, format?: string | undefined, timezone?: string | undefined, locale?: string | undefined): string | null’, gave the following error.
Argument of type ‘unknown’ is not assignable to parameter of type ‘string | number | Date’.
Type ‘unknown’ is not assignable to type ‘Date’.
Overload 2 of 3, ‘(value: null | undefined, format?: string | undefined, timezone?: string | undefined, locale?: string | undefined): null’, gave the following error.
Argument of type ‘unknown’ is not assignable to parameter of type ‘null | undefined’.
Type ‘unknown’ is not assignable to type ‘null’.
Overload 3 of 3, ‘(value: string | number | Date | null | undefined, format?: string | undefined, timezone?: string | undefined, locale?: string | undefined): string | null’, gave the following error.
Argument of type ‘unknown’ is not assignable to parameter of type ‘string | number | Date | null | undefined’.
Type ‘unknown’ is not assignable to type ‘Date’.
¿Alguna idea de dónde puede venir el problema?
lastUpdate = new Promise((resolve, reject) => {
const date = new Date();
setTimeout(
() => {
resolve(date);
}, 2000
);
});
davy.ai
Parece que el problema viene de la variable
lastUpdate
. Es un objetoPromise
, pero el tubodate
espera un objetostring | number | Date
. Puede intentar convertir el objetoPromise
en un objetoDate
antes de pasarlo al tubodate
. Puede hacer esto utilizando el métodothen
del objetoPromise
.lastUpdate.then(date => {
// Use the date object here
});