Zum Inhalt springen

Magic Number (ARCH3182)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

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.