# Proposal for Opaque Type Aliases

**URL:** <https://contributors.scala-lang.org/t/proposal-for-opaque-type-aliases/2947>\
**Category:** Scala Improvement Process\
**Created:** [March 19, 2019, 4:36pm UTC](https://contributors.scala-lang.org/t/proposal-for-opaque-type-aliases/2947 "2019-03-19T16:36:51Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![lihaoyi](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/lihaoyi/32/103_2.png) [@lihaoyi](https://contributors.scala-lang.org/u/lihaoyi)\
**Post date:** [March 20, 2019, 12:42am UTC](https://contributors.scala-lang.org/t/proposal-for-opaque-type-aliases/2947/6 "2019-03-20T00:42:54Z")

</div>

> An opaque type alias is almost always accompanied by a companion object, which can use [extension methods](https://contributors.scala-lang.org/t/proposal-to-add-extension-methods-to-the-language/2945) to enhance the opaque type alias with relevant methods:

I personally find this a pretty roundabout way of doing the same thing that value classes do: creating a bunch of instance methods that compile down to static functions operating on the unboxed type. Would it be possible to have a more value-class-like syntax?

```scala
object JSTypes {
  opaque type LargeInt = Double {
    def toDouble: Double = this

    def +(y: LargeInt): LargeInt = this.toDouble + x.toDouble
    ...
  }
  object LargeInt {
    def fromInt(x: Int): LargeInt = x.toDouble
  }
}

```

Otherwise it seems odd and boilerplatey to have a bunch of extension methods that aren’t _really_ extension methods: they’re just the primary set of methods of a particular type. The fact that the type is an opaque alias and the methods compile down to static functions isn’t really relevant.

---

_[View the full topic](https://contributors.scala-lang.org/t/proposal-for-opaque-type-aliases/2947)._
