Complete the code to declare an interface named Person.
interface [1] {
name: string;
age: number;
}The keyword interface is followed by the interface name, which should be Person with a capital P by convention.
Complete the code to add an optional property 'email' to the interface.
interface User {
id: number;
username: string;
[1]?: string;
}To declare an optional property in an interface, add a question mark ? after the property name. Here, the property name is email, and the question mark is placed after it in the code.
Fix the error in the interface declaration by completing the code.
interface Product {
id: number;
name: string[1]
price: number;
}
In TypeScript interfaces, each property declaration must end with a semicolon ;. The missing semicolon after name: string causes a syntax error.
Fill both blanks to declare an interface with a method that returns a string.
interface Logger {
log[1]: [2];
}The method log needs parentheses () to show it is a function, and the return type is string.
Fill all three blanks to declare an interface with an index signature for string keys and number values.
interface Scores {
[[1]: [2]]: [3];
}An index signature uses a variable name (like key) with a type (here string) inside square brackets, followed by the value type (number) after the colon.