# extending typealiases

**URL:** <https://forums.swift.org/t/extending-typealiases/5088>\
**Category:** Discussion\
**Created:** [February 6, 2017, 7:03am UTC](https://forums.swift.org/t/extending-typealiases/5088 "2017-02-06T07:03:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vatsal](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/vatsal/32/12722_2.png) [@vatsal](https://forums.swift.org/u/vatsal)\
**Post date:** [February 6, 2017, 7:03am UTC](https://forums.swift.org/t/extending-typealiases/5088/1 "2017-02-06T07:03:39Z")

</div>

+1 from me, it seems like a sensible improvement (albeit not a pressing one, as others have noted).

---

<div class="post-metadata">

**Author:** ![DevAndArtist](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/devandartist/32/287_2.png) [@DevAndArtist](https://forums.swift.org/u/DevAndArtist)\
**Post date:** [February 6, 2017, 5:51pm UTC](https://forums.swift.org/t/extending-typealiases/5088/2 "2017-02-06T17:51:12Z")

</div>

Just imagining the future. Iff this request will made into the language and we had typealias AnyObject = Any\<class\>, would the following be valid?

extension AnyObject {  
&nbsp;&nbsp;&nbsp;&nbsp;func foo()  
}

> **···**
>
> --  
> Adrian Zubarev  
> Sent with Airmail
> 
> Am 6. Februar 2017 um 08:03:52, Vatsal Manot via swift-evolution (swift-evolution@swift.org) schrieb:
> 
> +1 from me, it seems like a sensible improvement (albeit not a pressing one, as others have noted).  
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> swift-evolution mailing list  
> swift-evolution@swift.org  
> [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)

---

<div class="post-metadata">

**Author:** ![Anton\_Zhilin](https://avatars.discourse-cdn.com/v4/letter/a/e79b87/32.png) [@Anton\_Zhilin](https://forums.swift.org/u/Anton_Zhilin)\
**Post date:** [February 6, 2017, 6:06pm UTC](https://forums.swift.org/t/extending-typealiases/5088/3 "2017-02-06T18:06:15Z")

</div>

If I understand correctly, extension of a typealias should be strictly  
equivalent to extension of type on the right:

extension Any\<class\> {  
&nbsp;&nbsp;&nbsp;&nbsp;func foo()  
}

And Any\<...\> are not nominal types, so until we additionally allow  
extensions for non-nominal types, this will not compile.

Just imagining the future. Iff this request will made into the language and

> **···**
>
> 2017-02-06 20:51 GMT+03:00 Adrian Zubarev via swift-evolution \< swift-evolution@swift.org\>:
> 
> > we had typealias AnyObject = Any\<class\>, would the following be valid?
> > 
> > extension AnyObject {  
> > &nbsp;&nbsp;&nbsp;&nbsp;func foo()  
> > }
> > 
> > ​

---

<div class="post-metadata">

**Author:** ![Douglas\_Gregor](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/douglas_gregor/32/1362_2.png) [@Douglas\_Gregor](https://forums.swift.org/u/Douglas_Gregor)\
**Post date:** [February 6, 2017, 6:08pm UTC](https://forums.swift.org/t/extending-typealiases/5088/4 "2017-02-06T18:08:52Z")

</div>

Right.

Note that we capriciously banned extending AnyObject so y’all couldn’t sneak in code that would prevent AnyObject from turning into “an existential describing values of class type” :)

&nbsp;&nbsp;- Doug

> **···**
>
> > On Feb 6, 2017, at 10:06 AM, Anton Zhilin via swift-evolution \<swift-evolution@swift.org\> wrote:
> > 
> > If I understand correctly, extension of a typealias should be strictly equivalent to extension of type on the right:
> > 
> > extension Any\<class\> {  
> > &nbsp;&nbsp;&nbsp;&nbsp;func foo()  
> > }  
> > And Any\<...\> are not nominal types, so until we additionally allow extensions for non-nominal types, this will not compile.

---

<div class="post-metadata">

**Author:** ![DevAndArtist](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/devandartist/32/287_2.png) [@DevAndArtist](https://forums.swift.org/u/DevAndArtist)\
**Post date:** [February 6, 2017, 6:12pm UTC](https://forums.swift.org/t/extending-typealiases/5088/5 "2017-02-06T18:12:46Z")

</div>

Okay fine. I’m curious if we ever should be able to extend existentials. (Could be really handy.)

typealias FooView = UIView & Foo

extension FooView {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;func foo() { .. }  
}

// vs.  
extension UIView where Self : Foo { .. }

> **···**
>
> --  
> Adrian Zubarev  
> Sent with Airmail
> 
> Am 6. Februar 2017 um 19:06:16, Anton Zhilin (antonyzhilin@gmail.com) schrieb:
> 
> If I understand correctly, extension of a typealias should be strictly equivalent to extension of type on the right:
> 
> extension Any\<class\> {  
> &nbsp;&nbsp;&nbsp;&nbsp;func foo()  
> }  
> And  
> Any\<...\> are not nominal types, so until we additionally allow extensions for non-nominal types, this will not compile.
> 
> 2017-02-06 20:51 GMT+03:00 Adrian Zubarev via swift-evolution \<swift-evolution@swift.org\>:
> 
> Just imagining the future. Iff this request will made into the language and we had typealias AnyObject = Any\<class\>, would the following be valid?
> 
> extension AnyObject {  
> &nbsp;&nbsp;&nbsp;&nbsp;func foo()  
> }
