Ir al contenido

Magic Number (ARCH3182)

Esta página aún no está disponible en tu idioma.

Key typescript.quality.magic-number · Severity info · Category quality

Unnamed numeric literals inside expressions hide what they mean, and become hard to maintain when the same value is repeated. They should be extracted into named constants.

function priceWithTax(net: number): number {
return net * 1.18 + 30;
}
const VAT_RATE = 0.18;
const SHIPPING_FEE = 30;
function priceWithTax(net: number): number {
return net * (1 + VAT_RATE) + SHIPPING_FEE;
}

Extract numeric literals into descriptively named const or enum values.