# Generic typealiases with additional constraints?

**URL:** <https://forums.swift.org/t/generic-typealiases-with-additional-constraints/36204>\
**Category:** Compiler\
**Tags:** question\
**Created:** [May 6, 2020, 9:07am UTC](https://forums.swift.org/t/generic-typealiases-with-additional-constraints/36204 "2020-05-06T09:07:04Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![Slava\_Pestov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/slava_pestov/32/30204_2.png) [@Slava\_Pestov](https://forums.swift.org/u/Slava_Pestov)\
**Post date:** [May 6, 2020, 6:39pm UTC](https://forums.swift.org/t/generic-typealiases-with-additional-constraints/36204/14 "2020-05-06T18:39:51Z")

</div>

> [@Nevin](#):
>
> No, it doesn’t need to be an existential at all. It can retain the same “only usable as a generic constraint” restriction that PATs already have.

Right, but it would behave like an existential type when used in a generic constraint.

If I wrote this today

```swift
typealias Foo<T> = T where T : Sequence, T.Element == Int

```

Then it is not valid to write

```swift
func foo<T : Foo>(_: T) {}

```

But presumably, you could do that if you instead wrote

```swift
typealias Foo = Sequence where .Element == Int

```

So the syntax being proposed here is quite different than a generic typealias. It is more like a shorthand for a protocol type and a where clause to be expanded at the point of use (even if you decide not to allow it to be used as a type of a value).

In fact the above syntax is almost the same as the proposed syntax for generalized existentials:

```swift
Any<Sequence where .Element == Int>

```

The only difference is that the proposed typealias form forces you to name the new type.

---

_[View the full topic](https://forums.swift.org/t/generic-typealiases-with-additional-constraints/36204)._
