Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

380
Vistas
TS2339(TS) Property 'touches' does not exist on type 'Event'

I'm using VS2019 and TypeScript 4.3.5. The tsconfig.json file:

"compilerOptions": {
    "lib": [ "ES2017.String", "DOM", "ES2020.Intl", "ES2017" ],
    "target": "ES2017"
  }

points to "DOM", i.e. lib.dom.d.ts declarations file containing the touch event declarations. Here are two (of more):

interface Touch {
    readonly altitudeAngle: number;
    readonly azimuthAngle: number;
    readonly clientX: number;
    readonly clientY: number;
    readonly force: number;
    readonly identifier: number;
    readonly pageX: number;
    readonly pageY: number;
    readonly radiusX: number;
    readonly radiusY: number;
    readonly rotationAngle: number;
    readonly screenX: number;
    readonly screenY: number;
    readonly target: EventTarget;
    readonly touchType: TouchType;
}
interface TouchEventInit extends EventModifierInit {
    changedTouches?: Touch[];
    targetTouches?: Touch[];
    touches?: Touch[];
}

Yet, when I write the following line:

const event: Event = window.event;
for (var i = 0; i < event.touches.length; i++);

I get the error: TS2339(TS) Property 'touches' does not exist on type 'Event'.

I'm fairly new to typescript, any ideas what I'm doing wrong?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Event is the root type of all events in window, other events need to inherit that event

So there will be no touches property inside Event itself, you will need to find other extended types that has touches property such as TouchEvent

Also, event is a preserve name for the native window.event, try to use another name for your type.

Then your code should be like:

const customEvent: TouchEvent = window.event;
for (var i = 0; i < customEvent.touches.length; i++);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda