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.
C++ features type aliasing using the using
keyword.
using Distance = int;
C# since version 12 features type aliasing using the using
keyword.
[1]
using Distance = int;
Crystal features type aliasing using the alias
keyword.
[2]
alias Distance = Int32;
D features type aliasing using the alias
keyword.
[3]
alias Distance = int;
Dart features type aliasing using the typedef
keyword.
[4]
typedef Distance = int;
Elixir features type aliasing using @type
.
[5]
@type Distance :: integer
Elm features type aliasing using type alias
.
type alias Distance = Int
F3 features type aliasing using the type
keyword.
type Distance = int
Go features type aliasing using the type
keyword.
type Distance int
Hack features type aliasing using the newtype
keyword.
[6]
newtype Distance = int;
Haskell features type aliasing using the type
keyword.
[7]
type Distance = Int;
Julia features type aliasing. [8]
const Distance = Int
Kotlin features type aliasing using the typealias
keyword.
[9]
typealias Distance = Int
Nim features type aliasing. [10]
type
Distance* = int
OCaml features type aliasing. [11]
type distance = int
Python features type aliasing. [12]
Vector = listfloat
Type aliases may be marked with TypeAlias to make it explicit that the statement is a type alias declaration, not a normal variable assignment.
from typing import TypeAlias
Vector: TypeAlias = listfloat
Rust features type aliasing using the type
keyword.
[13]
type Point = (u8, u8);
Scala can create type aliases using opaque types. [14]
object Logarithms:
opaque type Logarithm = Double
Swift features type aliasing using the typealias
keyword.
typealias Distance = Int;
TypeScript features type aliasing using the type
keyword.
[15]
type Distance = number;
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.
C++ features type aliasing using the using
keyword.
using Distance = int;
C# since version 12 features type aliasing using the using
keyword.
[1]
using Distance = int;
Crystal features type aliasing using the alias
keyword.
[2]
alias Distance = Int32;
D features type aliasing using the alias
keyword.
[3]
alias Distance = int;
Dart features type aliasing using the typedef
keyword.
[4]
typedef Distance = int;
Elixir features type aliasing using @type
.
[5]
@type Distance :: integer
Elm features type aliasing using type alias
.
type alias Distance = Int
F3 features type aliasing using the type
keyword.
type Distance = int
Go features type aliasing using the type
keyword.
type Distance int
Hack features type aliasing using the newtype
keyword.
[6]
newtype Distance = int;
Haskell features type aliasing using the type
keyword.
[7]
type Distance = Int;
Julia features type aliasing. [8]
const Distance = Int
Kotlin features type aliasing using the typealias
keyword.
[9]
typealias Distance = Int
Nim features type aliasing. [10]
type
Distance* = int
OCaml features type aliasing. [11]
type distance = int
Python features type aliasing. [12]
Vector = listfloat
Type aliases may be marked with TypeAlias to make it explicit that the statement is a type alias declaration, not a normal variable assignment.
from typing import TypeAlias
Vector: TypeAlias = listfloat
Rust features type aliasing using the type
keyword.
[13]
type Point = (u8, u8);
Scala can create type aliases using opaque types. [14]
object Logarithms:
opaque type Logarithm = Double
Swift features type aliasing using the typealias
keyword.
typealias Distance = Int;
TypeScript features type aliasing using the type
keyword.
[15]
type Distance = number;