The typealias
keyword is overloaded to declare two kinds of types:
- Type Aliases (alternative name for an existing type)
- Associated Types (placeholder name to type used as part of a protocol)
Proposal SE-011 declares, “These two kinds of declarations are different and should use distinct keywords. This would emphasize the difference between them and reduce some of the confusion surrounding the use of associated types.”
What keyword do you think is a better replacement for typealias
? Help out in this poll.
Community responses, from the proposal:
- “I think this is a great idea; re-using typealias for associated types was a mistake.” -John McCall
- “Agreed.” -Chris Lattner
- “+1 to the proposal, emphasizing the distinction is important; and I like “associated” as the keyword for this purpose, too.” -Dmitri Gribenko
- “+1 for using a distinct keyword for associated types” -Ilya Belenkiy
4 Comments
How about `declare` or `deftype`?
I’m new to swift but it’s not clear to me why types associated with protocols are specified differently than types associated with (generic) classes which don’t need a keyword.
[…] of these things brought a lot of clarity to me about a complicated topic and helped me understand this Swift Evolution proposal. So I’d like to write down my initial understanding of Protocols with Associated Types […]
“typePlaceholder”?