Type aliasingType 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. ExampleC++C++ features type aliasing using the using Distance = int;
C#C# since version 12 features type aliasing using the using Distance = int;
CrystalCrystal features type aliasing using the alias Distance = Int32;
DD features type aliasing using the alias Distance = int;
DartDart features type aliasing using the typedef Distance = int;
ElixirElixir features type aliasing using @type Distance :: integer
ElmElm features type aliasing using type alias Distance = Int
F#F3 features type aliasing using the type Distance = int
GoGo features type aliasing using the type Distance = int
HackHack features type aliasing using the newtype Distance = int;
HaskellHaskell features type aliasing using the type Distance = Int;
JuliaJulia features type aliasing.[8] const Distance = Int
KotlinKotlin features type aliasing using the typealias Distance = Int
NimNim features type aliasing.[10] type
Distance* = int
OCamlOCaml features type aliasing.[11] type distance = int
PythonPython features type aliasing.[12] 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. from typing import TypeAlias
Vector: TypeAlias = list[float]
RustRust features type aliasing using the type Point = (u8, u8);
ScalaScala can create type aliases using opaque types.[14] object Logarithms:
opaque type Logarithm = Double
SwiftSwift features type aliasing using the typealias Distance = Int;
TypeScriptTypeScript features type aliasing using the type Distance = number;
ZigZig features type aliasing by assigning a data type to a constant.[16] const distance = u32;
References
|
Portal di Ensiklopedia Dunia