Lines Matching refs:type
100 - Functions are declared with argument types and return type: >
192 The argument types and return type need to be specified. The "any" type can
193 be used, type checking will then be done at runtime, like with legacy
200 list type, similar to TypeScript. For example, a list of numbers: >
220 There is no error for using the "_" argument multiple times. No type needs to
257 it is being compiled (to figure out the return type).
355 Declaring a variable with a type but without an initializer will initialize to
427 That is because the type needs to be inferred from the list item type, which
505 without `function()`. The argument types and return type will then be checked.
510 When using `function()` the resulting type is "func", a function with any
511 number of arguments and any return type (including void). The function can be
791 The key type can be string, number, bool or float. Other types result in an
814 following lines. This can lead to a long sequence of errors and need to type
861 type truthy when ~
887 When using "!" for inverting, there is no error for using any type and the
1046 :def[!] {name}([arguments])[: {return-type}]
1051 When {return-type} is omitted or is "void" the
1056 {name}: {type}
1058 {name}: {type} = {value}
1066 used. Syntax and type errors will be produced at that
1174 list<{type}>
1175 dict<{type}>
1179 func: {type}
1180 func({type}, ...)
1181 func({type}, ...): {type}
1184 tuple<a: {type}, b: {type}, ...>
1187 have the "void" type.
1189 There is no array type, use list<{type}> instead. For a list constant an
1194 func any kind of function reference, no type
1196 func: void any number and type of arguments, no return
1198 func: {type} any number and type of arguments with specific
1199 return type
1204 func(): {type} function with no argument and return type
1206 func({type}) function with argument type, does not return
1208 func({type}): {type} function with argument type and return type
1209 func(?{type}) function with type of optional argument, does
1211 func(...{type}) function with type of variable number of
1213 func({type}, ?{type}, ...{type}): {type}
1215 - type of mandatory argument
1216 - type of optional argument
1217 - type of variable number of arguments
1218 - return type
1220 If the return type is "void" the function does not return a value.
1226 Custom types can be defined with `:type`: >
1227 :type MyList list<string>
1249 Variable types and type casting ~
1251 Variables declared in Vim9 script or in a `:def` function have a type, either
1254 Global, buffer, window and tab page variables do not have a specific type, the
1255 value can be changed at any time, possibly changing the type. Therefore, in
1256 compiled code the "any" type is assumed.
1258 This can be a problem when the "any" type is undesired and the actual type is
1261 At compile time Vim doesn't know the type of "g:two" and the expression type
1262 becomes list<any>. An instruction is generated to check the list type before
1264 *type-casting*
1265 To avoid this, use a type cast: >
1268 error if it isn't. This is called type casting.
1270 The syntax of a type cast is: "<" {type} ">". There cannot be white space
1274 The semantics is that, if needed, a runtime type check is performed. The
1275 value is not actually changed. If you need to change the type, e.g. to change
1281 *type-inference*
1282 In general: Whenever the type is clear it can be omitted. For example, when
1284 var name = 0 # infers number type
1285 var name = 'hello' # infers string type
1287 The type of a list and dictionary comes from the common type of the values.
1288 If the values all have the same type, that type is used for the list or
1289 dictionary. If there is a mix of types, the "any" type is used. >
1294 The common type of function references, if they do not all have the same
1306 For script-local variables in Vim9 script the type is checked, also when the
1310 Stricter type checking ~
1311 *type-checking*
1319 before, if the value used matches the expected type. There will sometimes be
1325 One consequence is that the item type of a list or dict given to |map()| must
1333 If the item type was determined to be "any" it can change to a more specific
1334 type. E.g. when a list of mixed types gets changed to a list of strings: >
1591 instruction, at runtime the instruction would have to inspect the type of the
1592 arguments and decide what kind of addition to do. And when the type is
1598 The syntax for types, using <type> for compound types, is similar to Java. It
1599 is easy to understand and widely used. The type names are what were used in
1638 mix of static typing (a variable always has a known value type) and dynamic
1668 since a type cast can remove the immutable nature. Vim locks the value,
1692 shared, optional type checking is desirable. Also, type inference will avoid
1693 the need for specifying the type in many cases. The TypeScript syntax fits
1695 var name: string # string type is specified
1698 const greeting = 'hello' # string type is inferred
1706 1. Put the type before the name, like Dart: >
1710 2. Put the type after the variable name, but do not use a colon, like Go: >
1718 Since we use type inference the type can be left out when it can be inferred
1719 from the value. This means that after `var` we don't know if a type or a name
1721 Also, it will not be allowed to use a variable name that could be a type name,
1724 The chosen syntax, using a colon to separate the name from the type, adds
1739 In Vim9 type checking is stricter to avoid mistakes. Where a condition is
1748 If you have any type of value and want to use it as a boolean, use the `!!`
1799 compile them early, so that syntax and type errors are reported early?
1807 figure out their type, so that forward references are found, and only then
1816 cases it's better to do it later and accept that syntax and type errors are