Debe indicar explícitamente a TypeScript el tipo de HTMLElement que es su objetivo.
La forma de hacerlo es usar un tipo genérico para convertirlo en un tipo adecuado:
this.countUpdate.emit((<HTMLTextAreaElement>e.target).value./*...*/)
o (como quieras)
this.countUpdate.emit((e.target as HTMLTextAreaElement).value./*...*/)
o (de nuevo, cuestión de preferencia)
const target = e.target as HTMLTextAreaElement;
this.countUpdate.emit(target.value./*...*/)
Esto le permitirá a TypeScript saber que el elemento es un textareay conocerá la propiedad value.
Lo mismo se puede hacer con cualquier tipo de elemento HTML, siempre que le brinde a TypeScript un poco más de información sobre sus tipos, se lo devolverá con las sugerencias adecuadas y, por supuesto, con menos errores.
Para que sea más fácil para el futuro, es posible que desee definir directamente un evento con el tipo de su objetivo:
// create a new type HTMLElementEvent that has a target of type you pass
// type T must be a HTMLElement (e.g. HTMLTextAreaElement extends HTMLElement)
type HTMLElementEvent<T extends HTMLElement> = Event & {
target: T;
// probably you might want to add the currentTarget as well
// currentTarget: T;
}
// use it instead of Event
let e: HTMLElementEvent<HTMLTextAreaElement>;
console.log(e.target.value);
// or in the context of the given example
emitWordCount(e: HTMLElementEvent<HTMLTextAreaElement>) {
this.countUpdate.emit(e.target.value);
}
<img [src]="url"> <br/> <input type='file' (change)="showImg($event)">Componente:... this.url = event.target.result;A veces funciona, a veces no, cuando no es err eserror TS2339: Property 'result' does not exist on type 'EventTarget'Como sugirió, dígale a TS más al respecto, en el lugarHTMLTextAreaElementque probé,HTMLInputElemententoncestarget.valueno más err pero la imagen no se muestra.