Complete the code to declare a variable with a type in TypeScript.
let age: [1] = 25;
In TypeScript, you specify the type after the colon. Here, number is the correct type for the variable age.
Complete the code to define a function parameter type in TypeScript.
function greet(name: [1]) { console.log(`Hello, ${name}!`); }number or boolean for text data.any without reason.The parameter name should be a string because it represents text.
Fix the error by completing the type annotation for the array.
let scores: [1] = [10, 20, 30];
string[] when the array has numbers.boolean[] incorrectly.The array scores contains numbers, so its type is number[].
Fill in the blank to create a typed object in TypeScript.
let person: [1] = { name: 'Alice', age: 30 };
name and age.any or object without specific types.The object person has a name as a string and age as a number, so the type annotation matches that structure.
Fill all three blanks to create a typed function with parameters and return type.
function add(a: [1], b: [2]): [3] { return a + b; }
string types for parameters or return value.boolean as a type here.The function add takes two numbers and returns a number, so the parameter types and return type are number.