ts-type-forge
    Preparing search index...

    Type Alias Percent

    Percent: Index<101>

    Represents a percentage value as an integer. A union of integer literals from 0 to 100.

    Useful for representing progress, completion rates, or any value that can be expressed as a whole number percentage.

    const calculateProgress = (completed: number, total: number): Percent => {
    const percentage = Math.round((completed / total) * 100);
    return Math.min(100, Math.max(0, percentage)) as Percent;
    };

    const formatPercent = (value: Percent): string => `${value}%`;

    type FullProgress = 100 satisfies Percent;
    type HalfProgress = 50 satisfies Percent;
    type NoProgress = 0 satisfies Percent;

    // Usage in progress bars, loading indicators, etc.
    interface ProgressBarProps {
    progress: Percent;
    showLabel?: boolean;
    }