What is the reason behind TypeScript allowing arguments to be passed in the incorrect order?

Why doesn't TypeScript throw an error when the arguments are passed in the wrong order with these simple wrapper Types?

class FirstName {
    constructor(public value: string) {}
}

class LastName {
    constructor(public value: string) {}
}

function getFullName(fname: FirstName, sname: LastName){
    return `${fname.value} ${sname.value}`;
}

const fName = new FirstName("Dave");
const lName = new LastName("Cook");

var greeting = getFullName(lName, fName); // Why is there no compiler error?!

Answer №1

First and Last are instances containing a text: string attribute. It makes sense since TypeScript compiler verifies data types, not necessarily the names of the classes.

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

PHP Form encountering error due to JSON decoding following an AJAX request

After extensive research and much confusion, I have finally decided to seek help here. I am able to make my AJAX request post successfully in every format except JSON. I am eager to understand JSON so that I can start using it right away instead of learni ...

fetching numerous JSON documents using jquery

I am struggling to retrieve data from multiple JSON files and display it in a table. Despite being successful in appending data from one JSON file, I encountered issues when trying to pull data from multiple files. Here is my code: var uri = 'sharepo ...

Leveraging JavaScript to format an HTML string

Is there a way to format an HTML string similar to how it's done in an HTML editor like Netbeans with Alt-Shift-F? I'm looking for a JavaScript function or library that can achieve this. Any suggestions? ...

Interactive drop-down feature where the toggle option is displayed exclusively in the initial drop-down menu

I am currently integrating Dropdowns into a dynamic form. However, I have encountered an issue when adding more than one Dropdown. Upon clicking on any Dropdown button, the list only appears above the first Dropdown button and not the specific one I click ...

When attempting to utilize vue-resource, I encountered the error message: "Uncaught TypeError: window.Vue.use is not defined."

As a newcomer to Vue.js, I recently attempted to incorporate vue-resource into my project only to encounter the following error: Uncaught TypeError: window.Vue.use is not a function at vue-resource.js:1469 at vue-resource.js:10 at vue-resource.js: ...

Organize a list in AngularJS by breaking it down based on its headers and displaying them in

As someone who is new to angularJs, I am looking to convert an app to angularJs but I have encountered a roadblock: The custom accordion markup I am working with is as follows: <div class="accord_main_wrap" ng-controller="catController"> <di ...

Activate and focus on the text input field with a checkbox using AngularJS

Currently, I have a Bootstrap 3 input field with some prepended content along with a checkbox. My goal is to have the input field disabled until the checkbox is checked, and when it is checked, I not only want to enable the field but also set the focus on ...

Should I install @capacitor/android as a dev dependency in the package.json file of a React project?

I was pondering whether it would be better to add @capacitor/android, @capacitor/ios, and @capacitor/core as development dependencies. ...

Does moment/moment-timezone have a feature that allows for the conversion of a timezone name into a more easily comprehendible format?

Consider this example project where a timezone name needs to be converted to a more readable format. For instance: input: America/Los_Angeles output: America Los Angeles While "America/Los_Angeles" may seem human-readable, the requirement is to convert ...

Having trouble with Typescript accurately converting decimal numbers?

I am struggling with formatting decimals in my Typescript class. export myclass { deposit: number; } After converting my web API class to this Typescript class, my decimal amounts lose their additional zero. For example, 1.10 becomes 1.1. I want to keep ...

(pinia, vuex) I am having trouble accessing states and getters in main.js. What could be the reason for this issue?

Issue Resolved While the answer provided by @Po Wen Chen below was somewhat helpful, it didn't fully meet my requirements. Although data in proxy form continued to flow, the conditions were being met. The main issue was that every time the page was r ...

How can I use node-canvas to render three.js on the server-side?

I've been attempting to display images using the official three.js package, three, from npm with the canvas package also from npm. Unfortunately, I haven't had much success so far. I believe it should be doable since node-canvas (https://github. ...

Error encountered while utilizing fullCalendar: Uncaught TypeError - Unable to convert undefined or null to object

I'm encountering an issue while attempting to implement a FullCalendar in my Laravel project, and the error message I receive is: Uncaught TypeError: Cannot convert undefined or null to object at entries (<anonymous>) at e (jquery.min.js ...

What is the advantage of using event.target over directly referencing the element in eventListeners?

Suppose there are several buttons in an HTML file and the following code is executed: const buttons = document.querySelectorAll('button'); buttons.forEach((btn) => { btn.addEventListener('click', (e) => { console.log(btn.te ...

How can I set a default value for a v-select using a function in vue.js / vuetify?

I'm new to utilizing vuetify and I am curious if there is a method to set a value for a v-select using a function. My form can create an enterprise, leveraging apollo.js to connect with the database. Although all fields populate correctly when modifyi ...

What is the best way to ensure that text moves to the next line if it exceeds the boundaries of the parent div in either CSS or

I am looking to have the "remaining books count" and "remaining pens count text" automatically move to the next line below the numbers when they exceed two digits, causing an overflow in their parent div. Here is the code snippet I currently have: functi ...

Electron Developer: "An issue has occurred within the primary process - Callback function missing"

My Electron application runs smoothly when launched from the command line with npm start. However, I am now looking to distribute the application as user-friendly installers for Mac/Windows/Linux. To achieve this, I am utilizing Electron-Builder for packag ...

Running Python code with Selenium on an Azure server

While using Selenium to open web pages and extract content, I encountered an issue on my Azure server (which is command line based) as it does not support Chrome or Firefox browsers. Therefore, I am seeking an alternative method to run Python-based Seleniu ...

The response from NodeJS is not being properly parsed by Express or BodyParser

const express = require('express'); const bodyParser = require('body-parser'); const app = express(); const adminRoutes = require('./routes/admin'); const shopRoutes = require('./routes/shop'); // app.use(express.u ...

Interactive Button Animation using Three.js

After importing a Mesh element into three.js from an fbx file, I am looking to enhance it with an effect similar to that of a clickable button. I am aiming to achieve the same pushable button effect as demonstrated in the first button style found on http ...