0

I declared a value of type number and assigned a string to this value (typerror) in Typescript, I was expecting Typescript to refuse to compile this component to JavaScript, but Typescript did so despite the wrong input type. I want to know why?

typeScript:

type user={name:string, uid:string|number}

const login =(user:{name:string, uid:string|number})=>{
console.log(user)
return user
}

const user1=login({name:125,uid:125})
console.log(user1.name)

output in JavaScript format:

"use strict";
const login = (user) => {
    console.log(user);
    return user;
};
const user1 = login({ name: 125, uid: 125 });
console.log(user1.name);

error TS2322: Type 'number' is not assignable to type 'string'.

10 const user1=login({name:125,uid:125})
                      ~~~~

0 Answers0