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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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)
* [Access modifiers](#access-modifiers)
* [Methods](#methods)
* [Unions](#unions)
</td><td width=33% valign=top>
* [Unions](#unions)
* [Functions 2](#functions-2)
* [Pure functions by default](#pure-functions-by-default)
* [Mutable arguments](#mutable-arguments)
@ -104,6 +104,7 @@ For more details and troubleshooting, please visit the [vab GitHub repository](h
* [Interfaces](#interfaces)
* [Enums](#enums)
* [Sum types](#sum-types)
* [Type aliases](#type-aliases)
* [Option/Result types & error handling](#optionresult-types-and-error-handling)
* [Generics](#generics)
* [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 types are declared with `?Type`: