Actually, there is no doubt that creating a typealias for -let's say- String: typealias MyString = String wouldn't be that useful, (I would also assume that declaring a typealias for Dictionary with specific key/value type: typealias CustomDict = Dictionary<String, Int> might not be that useful to you.

However, when it comes to work with compound types you would definitely notice the benefits of type aliasing.

Example:

Consider that you are implementing manager which repeatedly work with closures with many parameters in its functions:

class MyManager {
    //...

    func foo(success: (_ data: Data, _ message: String, _ status: Int, _ isEnabled: Bool) -> (), failure: (_ error: Error, _ message: String, _ workaround: AnyObject) -> ()) {
        if isSuccess {
            success(..., ..., ..., ...)
        } else {
            failure(..., ..., ...)
        }
    }

    func bar(success: (_ data: Data, _ message: String, _ status: Int, _ isEnabled: Bool) -> (), failure: (_ error: Error, _ message: String, _ workaround: AnyObject) -> ()) {
        if isSuccess {
            success(..., ..., ..., ...)
        } else {
            failure(..., ..., ...)
        }
    }

    // ...
}

As you can see, the methods signatures looks really tedious! both of the methods take success and failure parameters, each one of them are closures with arguments; Also, for implementing similar functions, it is not that logical to keep copy-paste the parameters.

Implementing typealias for such a case would be so appropriate:

class MyManager {
    //...

    typealias Success = (_ data: Data, _ message: String, _ status: Int, _ isEnabled: Bool) -> ()
    typealias Failure = (_ error: Error, _ message: String, _ workaround: AnyObject) -> ()

    func foo(success: Success, failure: Failure) {
        if isSuccess {
            success(..., ..., ..., ...)
        } else {
            failure(..., ..., ...)
        }
    }

    func bar(success: Success, failure: Failure) {
        if isSuccess {
            success(..., ..., ..., ...)
        } else {
            failure(..., ..., ...)
        }
    }

    // ...
}

Thus it would be more expressive and readable.


Furthermore, you might want to check a medium story I posted about it.

Answer from Ahmad F on Stack Overflow
🌐
Python
typing.python.org › en › latest › spec › aliases.html
Type aliases — typing documentation
x = 1 # untyped global expression ... alias x: TypeAlias = "MyClass" # type alias · Note: The examples above illustrate implicit and explicit alias declarations in isolation. For the sake of backwards compatibility, type checkers should support both simultaneously, meaning an untyped ...
🌐
Programiz
programiz.com › swift-programming › typealias
Swift Typealias: How to use them and Why?
The main purpose of typealias is to make our code more readable, and clearer in context for human understanding.
🌐
Kotlin
kotlinlang.org › docs › type-aliases.html
Type aliases | Kotlin Documentation
Type aliases do not introduce new types. They are equivalent to the corresponding underlying types. When you add typealias Predicate<T> and use Predicate<Int> in your code, the Kotlin compiler always expands it to (Int) -> Boolean.
🌐
Wikipedia
en.wikipedia.org › wiki › Type_aliasing
Type aliasing - Wikipedia
October 21, 2025 - Type aliasing is a feature in some programming languages that allows creating a reference to a type using another name. It does not create a new type hence does not increase type safety. It can be used to shorten a long name. Languages allowing type aliasing include: C++, C# Crystal, D, Dart, ...
Top answer
1 of 3
31

Actually, there is no doubt that creating a typealias for -let's say- String: typealias MyString = String wouldn't be that useful, (I would also assume that declaring a typealias for Dictionary with specific key/value type: typealias CustomDict = Dictionary<String, Int> might not be that useful to you.

However, when it comes to work with compound types you would definitely notice the benefits of type aliasing.

Example:

Consider that you are implementing manager which repeatedly work with closures with many parameters in its functions:

class MyManager {
    //...

    func foo(success: (_ data: Data, _ message: String, _ status: Int, _ isEnabled: Bool) -> (), failure: (_ error: Error, _ message: String, _ workaround: AnyObject) -> ()) {
        if isSuccess {
            success(..., ..., ..., ...)
        } else {
            failure(..., ..., ...)
        }
    }

    func bar(success: (_ data: Data, _ message: String, _ status: Int, _ isEnabled: Bool) -> (), failure: (_ error: Error, _ message: String, _ workaround: AnyObject) -> ()) {
        if isSuccess {
            success(..., ..., ..., ...)
        } else {
            failure(..., ..., ...)
        }
    }

    // ...
}

As you can see, the methods signatures looks really tedious! both of the methods take success and failure parameters, each one of them are closures with arguments; Also, for implementing similar functions, it is not that logical to keep copy-paste the parameters.

Implementing typealias for such a case would be so appropriate:

class MyManager {
    //...

    typealias Success = (_ data: Data, _ message: String, _ status: Int, _ isEnabled: Bool) -> ()
    typealias Failure = (_ error: Error, _ message: String, _ workaround: AnyObject) -> ()

    func foo(success: Success, failure: Failure) {
        if isSuccess {
            success(..., ..., ..., ...)
        } else {
            failure(..., ..., ...)
        }
    }

    func bar(success: Success, failure: Failure) {
        if isSuccess {
            success(..., ..., ..., ...)
        } else {
            failure(..., ..., ...)
        }
    }

    // ...
}

Thus it would be more expressive and readable.


Furthermore, you might want to check a medium story I posted about it.

2 of 3
1

The common way to use typealias for me is working with closures:

typealias VoidClosure = () -> Void

func updateFrom(completion: @escaping VoidClosure) { }

🌐
SwiftLee
avanderlee.com › swiftlee › swift › typealias usage in swift
Typealias usage in Swift - SwiftLee
January 4, 2021 - A typealias in Swift is literally an alias for an existing type. Simple, isn’t it? They can be useful in making your code a bit more readable.
🌐
Appventure
appventure.me › posts › 2019-5-15-the-usefulness-of-typealiases-in-swift.html
AppVenture - The usefulness of typealiases in swift
A typealias can also be generic. One simple use case would be to enforce a container with a special meaning. Say we have an app that processes books. A book consists out of chapters, chapters consist out of pages. Fundamentally, those are just arrays though.
🌐
Python
peps.python.org › pep-0613
PEP 613 – Explicit Type Aliases | peps.python.org
Type aliases are user-specified types which may be as complex as any type hint, and are specified with a simple variable assignment on a module top level.
Find elsewhere
🌐
Artsy
artsy.github.io › blog › 2016 › 06 › 24 › typealias-for-great-good
Swift Type Aliases: Use Early and Often - Artsy Engineering
We’re still extending the view controller, but specifically we’re extending the typealias so that the extension has a helpful name. This is another way that typealias can help add semantic meaning to your code.
🌐
Sarunw
sarunw.com › posts › swift-typealias
Swift typealias: What is it and when to use it | Sarunw
March 24, 2022 - We use typealias to introduce a new semantic type out of the existing one. Type aliases don't create new types. They simply allow a name to refer to an existing type. We use this to give a more meaningful name to convey a clearer message to the reader.
🌐
Medium
medium.com › @sunshinejr › what-do-you-really-know-about-typealias-and-associatedtype-5ba25d45848e
Swift talks: What do you really know about typealias and associatedtype? | by Łukasz Mróz | Medium
April 12, 2018 - In extensions typealias means basically what it means in structs and so on. It is just an alias for a name - which is what we want in our case.
🌐
Donny Wals
donnywals.com › swifts-typealias-explained-with-five-examples
Swift’s typealias explained with five examples – Donny Wals
April 29, 2024 - Swift grants developers the ability to shadow certain types with an alternative name using the typealias keyword. We can use this feature to create tuples and closures that look like types, or we can use them to provide alternative names for existing objects.
🌐
Swift by Sundell
swiftbysundell.com › articles › the-power-of-type-aliases-in-swift
The power of type aliases in Swift | Swift by Sundell
typealias TimeInterval = Double · Using a type alias like that has pros and cons. Since TimeInterval isn’t actually its own type, but rather just an alias — it means that all Double values are valid TimeInterval values, and vice versa.
🌐
Flow
flow.org › type aliases
Type Aliases | Flow
Type aliases are just that: aliases. They don't create a different type, just another name for one. This means that a type alias is completely interchangeable with the type it is equal to.
🌐
Advanced Swift
advancedswift.com › typealias-examples
Typealias in Swift [+7 Examples Of Different Types]
February 18, 2022 - The typealias keyword in Swift defines another name for an existing type allowing a developer to add additional clarity to how an existing type is used.
🌐
Cppreference
en.cppreference.com › w › cpp › language › type_alias.html
Type alias, alias template (since C++11) - cppreference.com
Type alias is a name that refers to a previously defined type (similar to typedef) · Alias template is a name that refers to a family of types
🌐
Real Python
realpython.com › ref › glossary › type-alias
type alias | Python Glossary – Real Python
In Python, a type alias allows you to create an alternative name for an existing type. It’s a convenient way to make your type hints more readable · You can create a type alias by assigning a type to a variable name.
🌐
Reddit
reddit.com › r/learnpython › help understanding type aliases
r/learnpython on Reddit: Help understanding Type Aliases
April 28, 2025 -

Hi

Im reading through the typing documentation https://docs.python.org/3/library/typing.html and have a question that I cannot answer.

In the past when I wanted to use type aliases I would use code like Vector = list[float] (I think that I must have picked this up from a post on stack overflow or something).

However, in the document above it suggests using the code type Vector = list[float].

The difference between the two is that the data type is types.GenericAlias (the list[float]) for the first Vector and typing.TypeAliasType for the second Vector.

But besides that I am not really sure what is the difference between these two methods. Im not sure where the reason to use one over the other is. Im also not sure where the documntation is for the first example (maybe technically this is not a Type Alias).

Im not sure if anyone can help here?

🌐
Medium
medium.com › @talhasaygili › typealias-in-swift-5b82167953e9
Typealias in Swift. A type alias allows you to provide a… | by Talha Saygili | Medium
December 26, 2022 - Type aliases do not create new types. They simply allow a name to refer to an existing type. The main purpose of using Typealias is make our code clearer and human readable.