We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Inferred Return Types

So you know how we discussed that:

const myPowerLevel = 9000;

Is better TypeScript than:

const myPowerLevel: number = 9000;

What follows is a bit of personal opinion, but I think the same is generally true for function return (not parameter) types.

Instead of this:

function divide(a: number, b: number): number {
  return a / b;
}

We can write this:

function divide(a: number, b: number) {
  return a / b;
}

And TypeScript infers the output type as number.

Why Are Inferred Return Types Better?

Click to play video

Assignment

Support.ai needs a way to combine our internal system prompt with a user's prompt.

Complete the combinePrompts function, it should:

  1. Accept two string parameters: systemPrompt and userPrompt.
  2. Return them concatenated together separated by a newline \n. The system prompt should come first, followed by the user prompt.

The return type should be inferred as a string. Not explicitly specified.