Complete the code to define an interface for a user with a name and age.
export interface User {
name: string;
age: [1];
}The age property should be a number to represent the user's age.
Complete the code to add an optional email property to the interface.
export interface User {
name: string;
age: number;
email[1] string;
}The ?: syntax marks the email property as optional in the interface.
Fix the error in the interface by completing the property type correctly.
export interface Product {
id: number;
name: string;
tags: [1];
}string instead of string[] for an array.Array without a type parameter.The tags property should be an array of strings, so string[] is the correct type.
Fill both blanks to define an interface with a readonly id and a method that returns a string.
export interface Item {
[1] id: number;
getName(): [2];
}void as the return type when a string is expected.public keyword which is not valid in interfaces.The id is marked readonly to prevent changes. The getName method returns a string.
Fill all three blanks to create an interface with an index signature, a method, and an optional property.
export interface Dictionary {
[key: [1]]: [2];
getKeys(): [3][];
description?: string;
}number as the index key type when keys are strings.boolean as the value type incorrectly.The index signature uses string keys and string values. The getKeys method returns an array of strings.