Complete the code to declare a variable with automatic type inference.
let message = [1];TypeScript infers the type of message as string because it is initialized with a string literal.
Complete the function to let TypeScript infer the return type automatically.
function add(a: number, b: number) {
return [1];
}The function returns the sum of a and b. TypeScript infers the return type as number.
Fix the error by completing the code so TypeScript infers the correct type for the array.
const numbers = [1, 2, 3, [1]];
All elements are numbers, so TypeScript infers the array type as number[]. Adding a string or other types causes errors.
Fill both blanks to create an object with inferred types for its properties.
const user = {
name: [1],
age: [2]
};The object user has a name property inferred as string and an age property inferred as number.
Fill all three blanks to create a function with explicit parameter types and inferred return type.
const multiply = (x: [1], y: [2]) => [3];
The function multiply takes two number parameters and returns their product. TypeScript infers the return type as number.