Solución
solution.tsTypeScript
interface ChartConfig {
opacity?: number;
showAxes?: boolean;
title?: string;
}
export function normalizeChart(config: ChartConfig): Required<ChartConfig> {
// Usa ?? para asignar defaults respetando 0, false y "" como valores válidos
// return {
// opacity: config.opacity !== undefined ? config.opacity : 1,
// showAxes: config.showAxes !== undefined ? config.showAxes : true,
// title: config.title !== undefined ? config.title : "Sin título",
// };
return {
opacity: config.opacity ?? 1,
showAxes: config.showAxes ?? true,
title: config.title ?? "Sin título",
};
}0respuestas