Type aliasing
≈ 2 min read
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
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, Elixir, Elm, F#, Go, Hack, Haskell, Julia, Kotlin, Nim, OCaml, Python, Rust, Scala, Swift and TypeScript.
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, Elixir, Elm, F#, Go, Hack, Haskell, Julia, Kotlin, Nim, OCaml, Python, Rust, Scala, Swift and TypeScript. using Distance = int; using Distance = int; alias Distance = Int32; alias Distance = int; typedef Distance = int; @type Distance :: integer type alias Distance = Int type Distance = int Go features type aliasing using the type keyword and = . type Distance = int newtype Distance = int; type Distance = Int; const Distance = Int typealias Distance = Int type Distance* = int type distance = int Vector = list[float] Type aliases may be marked with TypeAlias to make it explicit that the statement is a type alias declaration, not a normal variable assignment. The use of (from PEP 613) is not required for the alias to function, but it explicitly tells static type checkers (like Mypy) that the assignment is a type declaration, not a runtime variable assignment. from typing import TypeAlias Vector: TypeAlias = list[float] type Point = (u8, u8); object Logarithms: opaque type Logarithm = Double typealias Distance = Int; type Distance = number; const distance = u32;
Text derived from https://en.wikipedia.org/w/index.php?oldid=1376291038 under CC BY-SA 4.0; modifications have been made.