Mercurial > vim
diff runtime/doc/vim9class.txt @ 33931:050160b94f02 v9.0.2162
patch 9.0.2162: Vim9: type documentation out-dated
Commit: https://github.com/vim/vim/commit/2a71b54d35361f3f0c24db88c672b426f8acc7b7
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Thu Dec 14 20:03:03 2023 +0100
patch 9.0.2162: Vim9: type documentation out-dated
Problem: Vim9: type documentation out-dated
Solution: Update documentation, fix typo in type alias
definition
closes: #13684
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 14 Dec 2023 20:15:06 +0100 |
parents | 56b32a00f325 |
children | 3bba09502b8d |
line wrap: on
line diff
--- a/runtime/doc/vim9class.txt +++ b/runtime/doc/vim9class.txt @@ -752,16 +752,38 @@ constructor methods. 7. Type definition *Vim9-type* *:type* -A type definition is giving a name to a type specification. This also known -type alias. For Example: > + *E1393* *E1395* *E1396* *E1397* *E1398* +A type definition is giving a name to a type specification. This is also +known as a "type alias". The type alias can be used wherever a built-in type +can be used. Example: > - :type ListOfStrings = list<string> + type ListOfStrings = list<string> + var s: ListOfStrings = ['a', 'b'] -The type alias can be used wherever a built-in type can be used. The type -alias name must start with an upper case character. A type alias can be -created only at the script level and not inside a function. A type alias can -be exported and used across scripts. + def ProcessStr(str: ListOfStrings): ListOfStrings + return str + enddef + echo ProcessStr(s) +< + *E1394* +A type alias name must start with an upper case character. Only existing +types can be aliased. + *E1399* +A type alias can be created only at the script level and not inside a +function. A type alias can be exported and used across scripts. + + *E1400* *E1401* *E1402* *E1403* *E1407* +A type alias cannot be used as an expression. A type alias cannot be used in +the left-hand-side of an assignment. + +For a type alias name, the |typename()| function returns the type that is +aliased: > + + type ListOfStudents = list<dict<any>> + echo typename(ListOfStudents) + typealias<list<dict<any>>> +< ============================================================================== 8. Enum *Vim9-enum* *:enum* *:endenum*