The Implicit ‘Any’ Type Error
Consider this addTwoNumbers
function:
export const addTwoNumbers = (a, b) => {
return a + b;
};
This function takes in a
and b
and adds them together.
It looks like perfectly valid JavaScript.
Running npm run exercise 01
in the terminal, we can see that our tests pass
Transcript
0:00 We've got some code here that looks like perfectly valid JavaScript, but TypeScript is yelling at us. We've got a function called add two numbers, which takes in a and b and adds them together. We can see in our terminal, in the tests that it's parsing here.
0:16 We can mess this up. If we want, we can say a-b and that will start failing our tests. We can see that it is actually working at runtime, but time script is not happy. Your job here is to work out why it's not happy. To decode these error messages, parameter a implicitly has in any type.
0:34 What on earth could that mean? Parameter b implicitly has in any type. Have a look in the documentation and see if you can find any hints as to what can fix these TypeScript errors.