Python 3.5+

Since Python 3.5 you may use typing module.

Quoting docs, A type alias is defined by assigning the type to the alias:

Copy# Python 3.5-3.8
from typing import List
Vector = List[float]

# Python 3.9+
Vector = list[float] # No import needed, lower case l

To learn more about enforcing types in Python you may want to get familiar with PEPs: PEP483 and PEP484.

Python historically was using duck-typing instead of strong typing and hadn't built-in way of declaring types before 3.5 release.

Answer from ลukasz Rogalski on Stack Overflow
๐ŸŒ
Python
typing.python.org โ€บ en โ€บ latest โ€บ spec โ€บ aliases.html
Type aliases โ€” typing documentation
The explicit alias declaration syntax with TypeAlias clearly differentiates between the three possible kinds of assignments: typed global expressions, untyped global expressions, and type aliases.
๐ŸŒ
Kotlin
kotlinlang.org โ€บ docs โ€บ type-aliases.html
Type aliases | Kotlin Documentation
December 2, 2025 - 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.
Discussions

How do you alias a type in Python? - Stack Overflow
Lucasz answer from 2015 provides this usage with links, which is from Python 3.9, not 3.10. Python 3.10 provides typing.TypeAlias as described in the answer by Jundiaius in 2022. "Modern" Python in Nov 2023 was Python 3.11 or Python 3.12. More on stackoverflow.com
๐ŸŒ stackoverflow.com
What is a typealias in Kotlin and how is it being used in this implementation? - Stack Overflow
I see there is a typealias keyword being used and then the invoke method is being called on that "type" Can someone please provide insight into what this is and how it is being used? typealias More on stackoverflow.com
๐ŸŒ stackoverflow.com
Help understanding Type Aliases
For the most part, there isn't much of a difference, although the newer syntax should be preferred if you don't plan to support older versions of Python. Basically, type Vector = list[float] is a newer way to write from typing import TypeAlias Vector: TypeAlias = list[float] and for the most part type analysis tools treat Vector = list[float] the same, despite technically containing different types. I think Mypy's documentation explains it better than I can: https://mypy.readthedocs.io/en/stable/kinds_of_types.html#type-aliases More on reddit.com
๐ŸŒ r/learnpython
2
3
April 28, 2025
swift - When to use typealias? - Stack Overflow
So far I understand that the typealias is a named alias of an existing type. By using typealias, I could do something like: typealias MyString = String var str: MyString? typealias Strings = [Str... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Dave Leeds on Kotlin
typealias.com
Dave Leeds on Kotlin
Take your Kotlin and Android skills to the next level.
๐ŸŒ
Medium
medium.com โ€บ @harshaag99 โ€บ understanding-typealias-in-swift-06e2a1791f5e
Understanding typealias in Swift. | by Harsha Agarwal | Medium
November 13, 2024 - In Swift, typealias is a way to give a new name to an existing type. This can be helpful to make your code easier to understand, especially when dealing with complex types.
๐ŸŒ
Programiz
programiz.com โ€บ swift-programming โ€บ typealias
Swift Typealias: How to use them and Why?
You can use typealias for all built in data Types as String, Int, Float etc.
Find elsewhere
๐ŸŒ
W3Schools
w3schools.com โ€บ typescript โ€บ typescript_aliases_and_interfaces.php
TypeScript Type Aliases and Interfaces
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
๐ŸŒ
The Rust Reference
doc.rust-lang.org โ€บ reference โ€บ items โ€บ type-aliases.html
Type aliases - The Rust Reference
Syntax TypeAlias โ†’ type IDENTIFIER GenericParams? ( : TypeParamBounds )? WhereClause? ( = Type WhereClause?
๐ŸŒ
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?

๐ŸŒ
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.
๐ŸŒ
LogRocket
blog.logrocket.com โ€บ home โ€บ mastering typealias in swift
Mastering typealias in Swift - LogRocket Blog
June 4, 2024 - In Swift, typealias is a function that gives a new name, or an alias, to an existing type. This type can be a concrete type, like Double or a custom structure, a compound type, like tuples, or a complex closure type.
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) { }

๐ŸŒ
Medium
blorenzop.medium.com โ€บ typealias-26baa57d81ae
Typealias in Swift: what is it and how to use it | Medium
March 1, 2025 - A typealias allows us to give a custom name to a specific type. Simple as that.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ typing.html
typing โ€” Support for type hints
1 week ago - Deprecated since version 3.12: TypeAlias is deprecated in favor of the type statement, which creates instances of TypeAliasType and which natively supports forward references. Note that while TypeAlias and TypeAliasType serve similar purposes and have similar names, they are distinct and the ...
๐ŸŒ
Sarunw
sarunw.com โ€บ posts โ€บ swift-typealias
Swift typealias: What is it and when to use it | Sarunw
March 24, 2022 - In general, a typealias function is to repurpose an existing type by giving a new name to it.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 72300063 โ€บ use-declared-but-not-defined-typealias-in-type-annotation
python - Use declared but not defined TypeAlias in type annotation? - Stack Overflow
a_type_alias : TypeAlias annotates that a_type_alias is a type of TypeAlias, but it does not define what it actually is. So yes, that won't work. The type annotation system just works with regular variables, and set[a_type_alias] needs to use the value of that variable at that time.
๐ŸŒ
Flow
flow.org โ€บ type aliases
Type Aliases | Flow
When you have complicated types that you want to reuse in multiple places, you
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ swift โ€บ swift-typealias
Swift - Typealias - GeeksforGeeks
February 14, 2022 - Basically it provides a new name to the existing type and always remembers it does not create a new type. Swift provides a keyword "typealias" which is similar to "typedef" keyword in C++. We can define more than one alias or another name for ...