When the parameter is incorrect, the click function still triggers an event

I have a button that triggers a function called check (resp is a reference in my HTML template)

<button
(click)="check(resp)">
clickMe
</button>

In my typescript code, I have:

check() {
console.log("check is clicked")
}

I can see the console output, but I am confused why the check function is called successfully. I am not expecting any arguments in the typescript code, but my template code passed an argument. I am expecting a signature mismatch error, but it is able to call successfully.

Answer №1

Unlike JavaScript, Typescript conducts type checking during the design phase rather than during runtime. The HTML template is kept separate from the .ts file, therefore it is not included in the compilation process. As a result, the Typescript compiler is unable to analyze it. Consequently, when the application is executed, it operates as standard JavaScript and does not enforce type checking.

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

Creating a generic array type in TypeScript that includes objects with every key of a specified interface

I am working with an interface called Item interface Item { location: string; description: string; } Additionally, I have a generic Field interface interface Field<T extends object> { name: keyof T; label: string; } I want to create an Arra ...

Is it possible to utilize ngIf to reuse a component when encountering a 404 error? How can the error be captured?

In my app-routin.module.ts file, I have a root component named HomeComponent that I reuse for unknown routes. const routes: Routes = [ { path: '', component: PrimaryComponent, data: { breadcrumb: 'PRIMARY'}, children: [ { p ...

Access specific properties of an object in TypeScript using dot notation with the

Can we use dot notation to extract nested object elements in TypeScript? interface Test { customer: { email: string; name: { firstName: string; }; }; }; type PickedTest = ExtractNested<Test, "customer.name.firstName"> ...

Angular request accessing CoinMarketCap API

Currently, I am immersing myself in the world of the latest CoinMarketCap API and navigating through the waters of data. The Node.js example below demonstrates how to make a request. But how can I achieve the same in Angular? Any tips or suggestions would ...

Obtaining data objects with Angular 2 from JSON

Recently, I received a URL that includes data arrays in JSON format. My goal is to retrieve and utilize all elements within it: However, when attempting this, I end up with everything but nothing specific. For instance: How can I access data.name or data. ...

A guide on activating the button once a user chooses an option from the dropdown menu in Ionic

I'm currently developing an Ionic Ecommerce app where I display products with their sizes. However, I'm facing an issue - I want to restrict users from adding the product to the cart without selecting a size first, but I'm struggling to impl ...

Interactive Bootstrap 4 button embedded within a sleek card component, complete with a dynamic click event

I am trying to create a basic card using bootstrap 4 with the following HTML code. My goal is to change the style of the card when it is clicked, but not when the buttons inside the card are clicked. Currently, clicking on the test1 button triggers both ...

Is it possible to eliminate the port number in Angular 7?

Currently, I am utilizing Angular in conjunction with an ASP.Net Web application. One interesting observation I've made is that when I use ng build, the app builds and runs on a URL without any port number. However, if I run the app using ng serve, it ...

Is there time support in the Angular 2 material date picker?

I recently upgraded to angular material version 2.0.0 beta.12 Although the <mat-datepicker> is functioning properly, I am interested in adding an option to select the hour (time) along with the date. After searching through the components listed on ...

The Subscription request did not trigger as expected

I encountered an issue where I needed to call two services in the OnInit step, but the second request was not being sent. As a workaround, I had to call them sequentially, which I believe is not the most efficient way to write the code. (Both services on t ...

How can you load an HTML page in Puppeteer without any CSS, JS, fonts, or images?

My current task involves using Puppeteer to scrape data from multiple pages in a short amount of time. However, upon closer inspection, I realized that the process is not as efficient as I would like it to be. This is because I am only interested in spec ...

What is the process for declaring a member variable as an extended type in TypeScript?

Is it possible to declare a "member variable" as an "extension object" rather than a static type (without relying on an interface)? Imagine something like this pseudocode: class Foo { bar -> extends Rectangle; constructor(barInstance:IRec ...

Implementing multer diskStorage with Typescript

I'm currently in the process of converting a node.js server to TypeScript. Here is what my function looks like in Node: const storage = multer.diskStorage({ destination: function (req, file, cb) { const dir = './uploads/'; ...

Ways to set a default value for a function that returns an unknown type in TypeScript

In my code, I have a customizedHook that returns a value of type typeXYZ || unknown. However, when I try to destructure the returned value, I encounter an error TS2339: Property 'xyz' does not exist on type 'unknown', even though the da ...

Encountering issues while attempting to transmit several files to backend in React/NestJS resulting in a BAD REQUEST error

My goal is to allow users to upload both their CV and image at the same time as a feature. However, every time I attempt to send both files simultaneously to the backend, I encounter a Bad Request error 400. I have made various attempts to troubleshoot th ...

Steps to develop a sub-route specifically for a single word

Take a look at this code: {path : 'recipes', component:RecipesComponent, children:[ {path:':id', component:RecipeDetailComponent}, {path:':new', component:NewRecipeComponent } ]}, No matter which link you use: h ...

Transform current JSON data into formatted JSON format using JavaScript or TypeScript

I have a JSON structure that needs to be reformatted in order to meet the requirements of an external service. Although the current format is complex and cannot be altered, I need to modify it to match the desired output for the external service. Current ...

Tips for effectively invoking an API within a Next.js application

I've been exploring the most effective method for calling an external API within a Next.js application recently. Given my experience in developing MERN stack applications, I typically rely on axios for handling API requests and utilize it within a use ...

What is the process for generating an array of objects using two separate arrays?

Is there a way to efficiently merge two arrays of varying lengths, with the number of items in each array being dynamically determined? I want to combine these arrays to create finalArray as the output. How can this be achieved? My goal is to append each ...

Retrieving Response Status Codes with Angular 4 and Express

When making GET requests to an Express REST API, I am setting res.status to 200 and returning data. However, in Angular, the response contains the data, but response.status always returns undefined. [UPDATE START] After trying Martin Adámek's sugge ...