Complete the code to declare a namespace named 'Shapes'.
namespace [1] { export const pi = 3.14; }
The namespace is named 'Shapes' to group related constants and types.
Complete the code to add a function 'area' inside the 'Shapes' namespace.
namespace Shapes {
export function [1](radius: number): number {
return pi * radius * radius;
}
}The function calculates the area of a circle, so it should be named 'area'.
Fix the error in the code by completing the namespace merging correctly.
namespace Shapes {
export const color = 'red';
}
namespace [1] {
export function getColor() {
return color;
}
}To merge declarations, the second namespace must have the same name 'Shapes'.
Fill both blanks to complete the merged namespace with a variable and a function accessing it.
namespace Shapes {
export let [1] = 'blue';
}
namespace Shapes {
export function get[2]() {
return [1];
}
}The variable is 'color' and the function is 'getColor' to access it.
Fill all three blanks to create a merged namespace with a type, a variable, and a function returning the variable.
namespace Shapes {
export type [1] = { radius: number };
export let [2]: [1] = { radius: 5 };
export function getRadius() {
return [3].radius;
}
}The type is 'Circle' (capitalized), the variable is 'circle' (lowercase), and the function returns circle.radius.