تخطَّ إلى المحتوى

Magic Number (ARCH3182)

هذا المحتوى غير متوفر بلغتك بعد.

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.