You could also do something like this, defining a type alias for battery size. 
Or `BatterySize = distinct int` if you want a type `BatterySize` that is 
distinct from any other int but still uses an int data type. That means you 
need to initialize 70 as `70.BatterySize` though, or create a `converter 
intToBatterySize(x: int): BatterySize = x.BatterySize`.
    
    
    type
      BatterySize = int
      ElectricCar = object
        year: int
        batterySize: BatterySize
    
    var c = ElectricCar(year: 2019, batterySize: 70)
    echo c.year
    echo c.batterySize
    
    
    Run

Reply via email to