Answer the question
In order to leave comments, you need to log in
Why is it possible to add a number and an array?
typescript is a strongly typed language. That is, it does not allow type conversion during the operation. However, the following code does not throw any error messages:
const multy = ( a, b ) => a + b;
const number = 5;
const array = [ 0, 1, 2 ];
const result1 = multy( number, array[ 2 ] );
const result2 = multy( number, array );
console.log(result1, typeof result1)
console.log(result2, typeof result2)
7 "number"
50,1,2 string
Answer the question
In order to leave comments, you need to log in
Well, add types to multy arguments and you will be happy. And then you drown for the typescript, but I don’t see a single type in the code.
Typescript is a language with weak static typing.
The tsconfig config allows you to configure the compiler in different ways - it can be configured so that it will only inform about errors and compile the code anyway. Google for keywords emit on error. And no implicit any, google it too.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question