Complete the code to declare an optional property in the interface.
interface User {
name: string;
age[1]: number;
}In TypeScript, optional properties in interfaces are marked with a question mark ? after the property name.
Complete the code to define an interface with an optional property.
interface Product {
id: number;
description[1]: string;
}The question mark ? after description marks it as optional in the interface.
Fix the error in the interface by correctly marking the optional property.
interface Settings {
theme: string;
fontSize[1]: number;
}The property fontSize should be marked optional with a question mark ? to indicate it may be missing.
Complete the code to create an interface with one required and one optional property.
interface Car {
model:: string;
year[1]: number;
}The required property model uses a colon : for type annotation. The optional property year uses a question mark ? to mark it optional.
Complete the code to define an interface with one optional and two required properties.
interface Book {
title:: string;
author:: string;
pages[1]: number;
}The properties title and author are required, so they use colon :. The property pages is optional, so it uses a question mark ?.