As far as I know, it is impossible to get this "type safety" that you are looking for type aliases. However, there is an alternative to the types of aliases that you can use for what you want: Value classes . Basically, a value class can give you a type without allocating a new object. Note that there are some restrictions on value classes that you do not have for type aliases.
To quote the scala documentation:
Correctness
Another use of value classes is to obtain a data type security type without the expense of allocating run time. For example, a data type fragment representing a distance might look like this:
class Meter(val value: Double) extends AnyVal { def +(m: Meter): Meter = new Meter(value + m.value) }
Code that adds two distances, for example
val x = new Meter(3.4) val y = new Meter(4.3) val z = x + y
will not actually allocate Meter instances, but will only use primitive doubles at runtime.
source share