From Wikipedia, the free encyclopedia

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.

Example

C++

C++ features type aliasing using the using keyword.

using Distance = int;

C#

C# since version 12 features type aliasing using the using keyword. [1]

using Distance = int;

Crystal

Crystal features type aliasing using the alias keyword. [2]

alias Distance = Int32;

D

D features type aliasing using the alias keyword. [3]

alias Distance = int;

Dart

Dart features type aliasing using the typedef keyword. [4]

typedef Distance = int;

Elixir

Elixir features type aliasing using @type. [5]

@type Distance :: integer

Elm

Elm features type aliasing using type alias.

type alias Distance = Int

F#

F3 features type aliasing using the type keyword.

type Distance = int

Go

Go features type aliasing using the type keyword.

type Distance int

Hack

Hack features type aliasing using the newtype keyword. [6]

newtype Distance = int;

Haskell

Haskell features type aliasing using the type keyword. [7]

type Distance = Int;

Julia

Julia features type aliasing. [8]

const Distance = Int

Kotlin

Kotlin features type aliasing using the typealias keyword. [9]

typealias Distance = Int

Nim

Nim features type aliasing. [10]

type
  Distance* = int

OCaml

OCaml features type aliasing. [11]

type distance = int

Python

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

Rust features type aliasing using the type keyword. [13]

type Point = (u8, u8);

Scala

Scala can create type aliases using opaque types. [14]

object Logarithms:
  opaque type Logarithm = Double

Swift

Swift features type aliasing using the typealias keyword.

typealias Distance = Int;

TypeScript

TypeScript features type aliasing using the type keyword. [15]

type Distance = number;

References

  1. ^ "Alias any type - C# 12.0 draft feature specifications". learn.microsoft.com. 16 August 2023. Retrieved 23 February 2024.
  2. ^ "alias - Crystal". crystal-lang.org. Retrieved 21 February 2024.
  3. ^ "Alias Alias - D Programming Language". dlang.org. Retrieved 18 June 2023.
  4. ^ "Typedefs". dart.dev. Retrieved 18 June 2023.
  5. ^ "Typespecs and behaviours". elixir-lang.github.com. Retrieved 23 June 2023.
  6. ^ "Types: Type Aliases". docs.hhvm.com. Retrieved 18 June 2023.
  7. ^ "Type synonym - HaskellWiki". wiki.haskell.org. Retrieved 18 June 2023.
  8. ^ "Types · The Julia Language". docs.julialang.org. Retrieved 23 June 2023.
  9. ^ "Type aliases | Kotlin". Kotlin Help. Retrieved 18 June 2023.
  10. ^ "Nim by Example - Types". nim-by-example.github.io. Retrieved 21 June 2023.
  11. ^ "OCaml reference manual". ocaml.org. Retrieved 23 April 2024.
  12. ^ "typing — Support for type hints". Python documentation. Python Software Foundation. Retrieved 18 June 2023.
  13. ^ "Type aliases - The Rust Reference". doc.rust-lang.org. Retrieved 18 June 2023.
  14. ^ "Opaque Types". Scala Documentation. Retrieved 18 June 2023.
  15. ^ "Documentation - Everyday Types". www.typescriptlang.org. Retrieved 18 June 2023.
From Wikipedia, the free encyclopedia

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.

Example

C++

C++ features type aliasing using the using keyword.

using Distance = int;

C#

C# since version 12 features type aliasing using the using keyword. [1]

using Distance = int;

Crystal

Crystal features type aliasing using the alias keyword. [2]

alias Distance = Int32;

D

D features type aliasing using the alias keyword. [3]

alias Distance = int;

Dart

Dart features type aliasing using the typedef keyword. [4]

typedef Distance = int;

Elixir

Elixir features type aliasing using @type. [5]

@type Distance :: integer

Elm

Elm features type aliasing using type alias.

type alias Distance = Int

F#

F3 features type aliasing using the type keyword.

type Distance = int

Go

Go features type aliasing using the type keyword.

type Distance int

Hack

Hack features type aliasing using the newtype keyword. [6]

newtype Distance = int;

Haskell

Haskell features type aliasing using the type keyword. [7]

type Distance = Int;

Julia

Julia features type aliasing. [8]

const Distance = Int

Kotlin

Kotlin features type aliasing using the typealias keyword. [9]

typealias Distance = Int

Nim

Nim features type aliasing. [10]

type
  Distance* = int

OCaml

OCaml features type aliasing. [11]

type distance = int

Python

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

Rust features type aliasing using the type keyword. [13]

type Point = (u8, u8);

Scala

Scala can create type aliases using opaque types. [14]

object Logarithms:
  opaque type Logarithm = Double

Swift

Swift features type aliasing using the typealias keyword.

typealias Distance = Int;

TypeScript

TypeScript features type aliasing using the type keyword. [15]

type Distance = number;

References

  1. ^ "Alias any type - C# 12.0 draft feature specifications". learn.microsoft.com. 16 August 2023. Retrieved 23 February 2024.
  2. ^ "alias - Crystal". crystal-lang.org. Retrieved 21 February 2024.
  3. ^ "Alias Alias - D Programming Language". dlang.org. Retrieved 18 June 2023.
  4. ^ "Typedefs". dart.dev. Retrieved 18 June 2023.
  5. ^ "Typespecs and behaviours". elixir-lang.github.com. Retrieved 23 June 2023.
  6. ^ "Types: Type Aliases". docs.hhvm.com. Retrieved 18 June 2023.
  7. ^ "Type synonym - HaskellWiki". wiki.haskell.org. Retrieved 18 June 2023.
  8. ^ "Types · The Julia Language". docs.julialang.org. Retrieved 23 June 2023.
  9. ^ "Type aliases | Kotlin". Kotlin Help. Retrieved 18 June 2023.
  10. ^ "Nim by Example - Types". nim-by-example.github.io. Retrieved 21 June 2023.
  11. ^ "OCaml reference manual". ocaml.org. Retrieved 23 April 2024.
  12. ^ "typing — Support for type hints". Python documentation. Python Software Foundation. Retrieved 18 June 2023.
  13. ^ "Type aliases - The Rust Reference". doc.rust-lang.org. Retrieved 18 June 2023.
  14. ^ "Opaque Types". Scala Documentation. Retrieved 18 June 2023.
  15. ^ "Documentation - Everyday Types". www.typescriptlang.org. Retrieved 18 June 2023.

Videos

Youtube | Vimeo | Bing

Websites

Google | Yahoo | Bing

Encyclopedia

Google | Yahoo | Bing

Facebook