1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

doc: Add a note on how to define type aliases. (#9466)

This commit is contained in:
Alberto González Palomo
2021-03-26 18:50:29 +01:00
committed by GitHub
parent 6f5259571d
commit 762036963c

View File

@@ -86,10 +86,10 @@ For more details and troubleshooting, please visit the [vab GitHub repository](h
* [Short struct literal syntax](#short-struct-initialization-syntax) * [Short struct literal syntax](#short-struct-initialization-syntax)
* [Access modifiers](#access-modifiers) * [Access modifiers](#access-modifiers)
* [Methods](#methods) * [Methods](#methods)
* [Unions](#unions)
</td><td width=33% valign=top> </td><td width=33% valign=top>
* [Unions](#unions)
* [Functions 2](#functions-2) * [Functions 2](#functions-2)
* [Pure functions by default](#pure-functions-by-default) * [Pure functions by default](#pure-functions-by-default)
* [Mutable arguments](#mutable-arguments) * [Mutable arguments](#mutable-arguments)
@@ -104,6 +104,7 @@ For more details and troubleshooting, please visit the [vab GitHub repository](h
* [Interfaces](#interfaces) * [Interfaces](#interfaces)
* [Enums](#enums) * [Enums](#enums)
* [Sum types](#sum-types) * [Sum types](#sum-types)
* [Type aliases](#type-aliases)
* [Option/Result types & error handling](#optionresult-types-and-error-handling) * [Option/Result types & error handling](#optionresult-types-and-error-handling)
* [Generics](#generics) * [Generics](#generics)
* [Concurrency](#concurrency) * [Concurrency](#concurrency)
@@ -2365,6 +2366,12 @@ fn pass_time(w World) {
} }
``` ```
### Type aliases
To define a new type `NewType` as an alias for `ExistingType`,
do `type NewType = ExistingType`.<br/>
This is a special case of a [sum type](#sum-types) declaration.
### Option/Result types and error handling ### Option/Result types and error handling
Option types are declared with `?Type`: Option types are declared with `?Type`: