Error TS2304: Unable to locate the word 'InputEvent'

While exploring the topic of whether TypeScript has type definitions for InputEvent, I experimented with using @types/dom-inputevent in my Angular 7 project. However, I kept encountering the error TS2304: Cannot find name 'InputEvent' whenever I tried to utilize it.

I'm curious if there is a specific process or step needed to properly "register" InputEvent in an Angular project, or if this issue may be a bug?

If a straightforward solution isn't readily available, I'm simply seeking an alternative method to achieve similar results as event.data with InputEvent.

Any insights or suggestions would be greatly appreciated!

Answer №1

Encountering a similar issue while attempting to utilize @types/dom-inputevent in unit tests for an Angular 6 application, I discovered the root of the problem. It turned out that my tsconfig.spec.js file had a specific 'types' declaration, causing conflicts with the typeRoots setting in the parent tsconfig.json file.

tsconfig.json (irrelevant details excluded)

{
  "compilerOptions": {
     "typeRoots": [
       "node_modules/@types"
     ]
  }
}

tsconfig.spec.js (irrelevant details omitted)

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
  "types": [
    "jasmine",
    "node"
  ]
}

The explicit 'types' entry in tsconfig.spec.js took precedence over the 'typeRoots' setting, restricting access to only @types/jasmine and @types/node during compilation of my unit tests. More information can be found here: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types.

To resolve this issue, I needed to include dom-inputevent in the 'types' list as shown below:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
  "types": [
    "jasmine",
    "node",
    "dom-inputevent"
  ]
}

Alternatively, removing the 'types' entry entirely would prompt the 'typeRoots' to search for all types under node_modules/@types, thereby encompassing @types/dom-inputevent as well.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Optimizing Angular 2's Efficiency: A Deep Dive into Change Detection and Performance Metrics (1000 calls measured

As a newcomer to Angular 2, I recently inherited a project using the framework. Upon assessing the app's performance, I noticed it was running quite slowly and causing issues. I investigated further and discovered that many ngIf's and ngFor&apo ...

How to Decode JSON Data in Angular 2/4 with the Help of HttpClientModule

I am receiving this JSON structure from my asp.net core API: { "contentType": null, "serializerSettings": null, "statusCode": null, "value": { "productName": "Test", "shortDescription": "Test 123", "imageUri": "https://bla.com/bla", ...

Retrieve HTTP status code within Angular 2 component from a Service

I encountered an issue while trying to return an object from my Http Service's catch block to my component: Below is the code snippet from my service: login(username,password){ let headers = new Headers(); headers.append('Conten ...

The type FormGroup<any> lacks the controls and registerControl properties compared to AbstractControl<any>

I've been developing a reactive nested form inspired by this YouTube tutorial - https://www.youtube.com/watch?v=DEuTcG8DxUI Overall, everything is working fine, except for the following error - Below are my files. home.component.ts import { Compone ...

Tips for transitioning from Angular 4 to Angular 5

As a newcomer to Angular, I recently launched a project using Angular CLI. However, a new version has been released since then. I am looking to update my project to the latest version of Angular (v5). How should I go about migrating it? ...

What is the best method to completely uninstall Apollo-Angular along with all of its dependencies?

Once I added apollo-angular and @apollo/client to my project, I quickly realized that I no longer needed them. However, simply using "npm uninstall apollo-angular" and "npm uninstall @apollo/client" only removed the main folders but left behind other Apoll ...

Typescript's forEach method allows for iterating through each element in

I am currently handling graphql data that is structured like this: "userRelations": [ { "relatedUser": { "id": 4, "firstName": "Jack", "lastName": "Miller" }, "type": "FRIEND" }, { "relatedUser": ...

Trouble accessing JSON object keys in Angular2 (rc.6)

Embarking on my initial Angular2 (rc.6) endeavor. I've managed to send a JSON object to a component successfully, but I'm facing difficulties accessing its key values in the template. SERVICE (excerpt): @Injectable() export class SongService { ...

The string is being added to an array twice

I am managing two sets of lists where strings will be transferred between them. One set contains a list of strings for searching purposes. The other set contains the same list of strings but is not used as a filter. The second set functions in a similar ...

What is the best way to insert CSS code into a custom Vue directive file?

I need a solution that applies a gradient background to the parent div in case an image fails to load. I've attempted to create a directive for this purpose: export default { bind(el: any, binding: any) { try { ..... ...

Issue encountered when utilizing properties in a Vue.js instance with vue-class-components and TypeScript

I am looking to create a global variable for my server's URL. In my main.ts file, I added the following line: Vue.prototype.$apiUrl = "http://localhost:3000"; Then, when trying to use it in my App.vue file: console.log(this.$apiUrl) The URL is disp ...

The interpolated string type is not allowed to be utilized for indexing a record that has the identical type as the key

I'm attempting to utilize an interpolated string form to access a Record type using a key that should match the record's key type. Unfortunately, it doesn't appear to be functioning as expected. Here is a simple example: type TypeOfKey = `c ...

Unit Testing Angular: Passing FormGroupDirective into a Function

I am currently writing unit tests for a function that takes a parameter of type FormGroupDirective. I have been able to test most of the logic, but I'm unsure about what to pass as a parameter when calling the resetForm() function. Here is the code sn ...

Angular 5: The templateRef.createEmbeddedView method is throwing an error and is not functioning as

Having trouble getting this code to function properly in Angular 5: import { Component, ViewChild, TemplateRef, ViewContainerRef } from '@angular/core'; @Component({ selector: 'vcr', template: ` <template #tpl> & ...

Is it recommended to utilize the `never` type for a function that invokes `location.replace`?

I'm facing an issue with my TypeScript code snippet: function askLogin(): never { location.replace('/login'); } The TypeScript compiler is flagging an error: A function returning 'never' cannot have a reachable end point. Do ...

Error message: NextJs throws aReferenceError when trying to access the document object on page refresh

encountered the error ReferenceError: document is not defined when attempting to refresh the page I am working on creating a component using react-quill and then calling that component within a page. This is my component : import React, { useState } from ...

Run a function after all xmlHttpRequests have finished executing

OVERVIEW My website relies on an API to fetch data, making multiple post and get requests to a server upon opening. While we know how long each individual call takes, determining the total time for all calls to complete is challenging. SCENARIO For inst ...

Spotlight a newly generated element produced by the*ngFor directive within Angular 2

In my application, I have a collection of words that are displayed or hidden using *ngFor based on their 'hidden' property. You can view the example on Plunker. The issue arises when the word list becomes extensive, making it challenging to ide ...

Tips for leveraging angular CLI's async import feature with webpack

I've been attempting to utilize webpack's (2.2.1) async module loading as outlined in the documentation. In addition, I have explored various examples for reference. However, I keep encountering the error message Declaration or statement expecte ...

How to customize the radio button style in Angular 11 by changing the text color

Hey guys, I'm working with these radio buttons and have a few questions: <form [formGroup]="myForm" class="location_filter"> <label style="font-weight: 500; color: #C0C0C0">Select a button: </label& ...