Complete the code to define a strict configuration object with a required 'url' property.
const config: { url: string } = { url: [1] };The 'url' property must be a string, so it needs to be enclosed in quotes.
Complete the code to add an optional 'timeout' property of type number to the configuration object.
interface Config {
url: string;
timeout[1] number;
}
const config: Config = { url: "https://api.example.com" };The optional property syntax in TypeScript uses a question mark before the colon, like timeout?: number;.
Fix the error in the code by completing the type for the configuration object to prevent extra properties.
type Config = {
url: string;
timeout?: number;
} & [1];
const config: Config = {
url: "https://api.example.com",
timeout: 5000,
retries: 3
};Using & never prevents extra properties by making the type impossible to extend with unknown keys.
Fill both blanks to create a strict configuration object type that only allows 'url' and 'timeout' properties.
type Config = {
url: string;
timeout?: number;
} & { [K in keyof [1]]?: never };
const config: Config = { url: "https://api.example.com" };Using Omit gets keys not allowed, and Pick picks allowed keys to forbid others.
Fill all three blanks to define a strict configuration object with a required 'url', optional 'timeout', and no extra properties allowed.
type Config = {
url: string;
timeout?: number;
};
const config: Config & [1] = {
url: "https://api.example.com",
timeout: 3000,
[2]: 5,
[3]: true
};The intersection with { [key: string]: never } forbids extra properties. The extra keys 'retries' and 'debug' cause errors.