๐ŸŒ
The Rust Reference
doc.rust-lang.org โ€บ reference โ€บ items โ€บ type-aliases.html
Type aliases - The Rust Reference
For example, the following defines the type Point as a synonym for the type (u8, u8), the type of pairs of unsigned 8 bit integers: #![allow(unused)] fn main() { type Point = (u8, u8); let p: Point = (41, 68); } ... #![allow(unused)] fn main() { struct MyStruct(u32); use MyStruct as UseAlias; type TypeAlias = MyStruct; let _ = UseAlias(5); // OK let _ = TypeAlias(5); // Doesn't work }
๐ŸŒ
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
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, ...
๐ŸŒ
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.
๐ŸŒ
Hhvm
docs.hhvm.com โ€บ type aliases
Type Aliases | Hack & HHVM Documentation
We can create an alias name for a type, and it is common to do so for non-trivial tuple and shape types. Once such a type alias has been defined,
๐ŸŒ
Artsy
artsy.github.io โ€บ blog โ€บ 2016 โ€บ 06 โ€บ 24 โ€บ typealias-for-great-good
Swift Type Aliases: Use Early and Often - Artsy Engineering
But before I dig into how typealias is useful, letโ€™s review what it is to make sure weโ€™re all on the same page. Developers use typealias to create a new type identifier thatโ€™s a synonym for another type.
๐ŸŒ
Cppreference
en.cppreference.com โ€บ w โ€บ cpp โ€บ language โ€บ type_alias.html
Type alias, alias template (since C++11) - cppreference.com
1) A type alias declaration introduces a name which can be used as a synonym for the type denoted by type-id. It does not introduce a new type and it cannot change the meaning of an existing type name. There is no difference between a type alias declaration and typedef declaration.
Top answer
1 of 4
42

type A = string creates an alias for string. Whenever you use A in your code, it works just like string. So for example, you can't define methods on it.

type A string defines a new type, which has the same representation as string. You can convert between an A and string at zero cost (because they are the same), but you can define methods on your new type, and reflection will know about the type A.

For example (on the playground)

Copypackage main

import (
    "fmt"
)

type A = string
type B string

func main() {
    var a A = "hello"
    var b B = "hello"
    fmt.Printf("a is %T\nb is %T\n", a, b)
}

Output:

Copya is string
b is main.B
2 of 4
17

To be clear on terms, these both are type declarations.

Copytype A = string

This is called alias declaration. I.e. you creating an alias to a type. Basically, there's no difference between type and alias. You can define methods on alias and they will be available for initial type instances. Example:

Copytype A struct {}

type B = A

func (B) print() {
    fmt.Println("B")
}

func main() {
    a := A{}
    b := B{}

    a.print()  // OUTPUT: B
    b.print()  // OUTPUT: B
}

Although, in your particular example type A = string you can't define methods on it, because string is non-local type(there was a proposal to add ability to create methods for non-local types but it got rejected).

Your second case type A string is type definition. Basically it's creating new type that has all fields of original type, but not it's methods. Example:

Copytype A struct {}

func (A) print() {
    fmt.Println("A")
}

type B A

func (B) print() {
    fmt.Println("B")
}

func main() {
    a := A{}
    b := B{}

    a.print()  // OUTPUT: A
    b.print()  // OUTPUT: B
}
Find elsewhere
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ cpp โ€บ cpp โ€บ aliases-and-typedefs-cpp
Aliases and typedefs (C++) | Microsoft Learn
You can use an alias declaration to declare a name to use as a synonym for a previously declared type. (This mechanism is also referred to informally as a type alias).
๐ŸŒ
Sarunw
sarunw.com โ€บ posts โ€บ swift-typealias
Swift typealias: What is it and when to use it | Sarunw
March 24, 2022 - A type alias is a powerful tool. It gives you the ability to give a nickname or synonym to an existing type, giving a more meaningful name to convey a clearer message to the reader.
๐ŸŒ
Medium
medium.com โ€บ @riztech.dev โ€บ understanding-type-aliases-in-kotlin-a-simple-guide-5a819954e2d7
Understanding Type Aliases in Kotlin: A Simple Guide | by Rizwanul Haque | Medium
May 31, 2024 - typealias StringList = List<String> typealias StringMap = Map<String, String> fun processStringList(list: StringList) { // Function implementation } fun processStringMap(map: StringMap) { // Function implementation }
๐ŸŒ
HaskellWiki
wiki.haskell.org โ€บ Type_synonym
Type synonym - HaskellWiki
A type synonym is a new name for an existing type. Values of different synonyms of the same type are entirely compatible.
๐ŸŒ
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?

๐ŸŒ
Python.org
discuss.python.org โ€บ python help
PEP 695 type aliases not suitable as replacement for typing.TypeAlias? - Python Help - Discussions on Python.org
January 16, 2024 - I reported this in github, but I am wondering if my sense of what people use type aliases for is completely wrong. But it seems to me that although PEP 695 type aliases are the blessed replacement for the now-deprecated typing.TypeAlias, they are functionally not suitable as replacement.
๐ŸŒ
Programiz
programiz.com โ€บ swift-programming โ€บ typealias
Swift Typealias: How to use them and Why?
In this article, you will learn about typealias and its use cases in Swift.
๐ŸŒ
Dave Leeds on Kotlin
typealias.com โ€บ guides โ€บ all-about-type-aliases
All About Type Aliases in Kotlin - Dave Leeds on Kotlin
May 14, 2018 - // Generics with Type Parameters typealias MultivaluedMap<K, V> = HashMap<K, List<V>> typealias Lookup<T> = HashMap<T, T> // Generics with Concrete Type Arguments typealias Users = ArrayList<User> // Type Projections typealias Strings = Array<out String> typealias OutArray<T> = Array<out T> typealias AnyIterable = Iterable<*> // Objects (including Companion Objects) typealias RegexUtil = Regex.Companion // Function Types typealias ClickHandler = (View) -> Unit // Lambda with Receiver typealias IntentInitializer = Intent.() -> Unit // Nested Classes and Interfaces typealias NotificationBuilder = NotificationCompat.Builder typealias OnPermissionResult = ActivityCompat.OnRequestPermissionsResultCallback // Enums typealias Direction = kotlin.io.FileWalkDirection // (but you cannot alias a single enum *entry*) // Annotation typealias Multifile = JvmMultifileClass
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) { }

๐ŸŒ
GitHub
gist.github.com โ€บ simonwhitaker โ€บ 3a24d669b26b4f373690c6eb113c3ae7
python-type-alias-vs-newtype.md ยท GitHub
Type aliases are exactly that; simply an alias for a type. Anywhere you refer to the original type (e.g. list[float]), you can now also refer to it as the alias (e.g. Vector) instead; they are interchangeable synonyms.