Document numeric intent
Use a meaningful name such as DurationSeconds or RetryCount when a codebase repeatedly passes numbers with a specific domain meaning.
TypeScript · Type Alias
A number type alias assigns a domain-specific name to TypeScript’s existing number type. It improves readability but does not create a distinct or nominal numeric type.
A type alias gives the existing number type another name; it does not create a distinct type. Values typed with the alias have the same assignability and behavior as values typed directly as number, so the alias is mainly useful for domain terminology or consistent declarations in a large codebase.
type AliasName = number;type keyword followed by an identifier, an equals sign, and the aliased type.type Second = number;, which names the built-in numeric type.type NumberValue = number;
function add(a: NumberValue, b: NumberValue): NumberValue {
return a + b;
}
const total: NumberValue = add(2.5, 3.5);
console.log(total);The alias documents that these values are numbers while preserving the original number type.
Use a meaningful name such as DurationSeconds or RetryCount when a codebase repeatedly passes numbers with a specific domain meaning.
Give a shared numeric concept one canonical name across function parameters, return types, and object properties.
Expose a public API using a stable domain term while retaining ordinary number assignability.
A type alias such as type NumberValue = number introduces an alternate name for the existing number type. It does not create a new nominal type, so NumberValue and number are assignable in the same way.
Follow-up: How would you model a union instead? Use a type alias such as type Result = number | string; aliases can name unions as well as primitives.
It can make a repeated primitive clearer by expressing domain intent, such as type DurationSeconds = number. The compiler still treats the alias as number, so it does not validate units or distinguish durations from other numbers.
Follow-up: How can stronger distinction be added? Use a branded or otherwise structurally distinctive type pattern rather than a plain primitive alias.
Type aliases can name primitives, unions, tuples, object types, and other types that would otherwise be written directly. For a plain number alias, the declaration is type Name = number;.
Follow-up: Can a type alias be generic? Yes; the documentation shows aliases with type parameters, such as type Container<T> = { value: T }.
numbertype aliasesinterfacesunion typestuple typesgeneric type aliases