By now, we’ve made a pretty convincing case that type annotations are very useful and should always be used unless there’s a very good reason not to. They make everything neat and aid in understanding our code.

For these reasons, it is often preferred to use type annotations for functions, even when those functions don’t return anything. Example:

function logGreeting(name: string){ console.log(`Hello, ${name}!`) }

The function logGreeting() simply logs a greeting to the console. There is no returned value, so we must treat the return type as void. A proper type annotation for this function would look like this:

function logGreeting(name:string): void{ console.log(`Hello, ${name}!`) }



Use TypeScript to check this fruit salad code for type errors.


It looks like the type annotation for the return type of makeFruitSalad() isn’t quite right. Please correct this!

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?