Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

381
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda