Any
Description: | When used in a type annotation or signature, matches any type. In other words, a "superset" of other types. |
Annotation: | any |
Literal syntax: | N/A - Any literal value can be assigned to an any type |
Casts: | N/A |
Additional Language Notes
A variable defined as
any
takes on the type of its currently assigned value. In other words,describe
will never return theany
type itself. See the examples below.any
is commonly used to:Annotate a variable that can accept any type
Example - Declare a mutable variable that can accept any type
let q = false # Start by assigning a null (nothing type) to x # to indicate that it hasn't been processed mut x: any = null if $q { $x = 'Yes' } else { $x = 'No' } $x # =>'No', which is a string
Annotate a command parameter that can accept any type
def takes-anything [v: any] -> string { $v | describe } takes-anything 42 # => int takes-anything foo # => string
- Annotate a type signature for a command that can accept any type as input or might output any type
def passthrough [] any -> any { $in } "Virat Kohli" | passthrough | describe # =>string {||} | passthrough | describe # =>closure
Annotate a
list
to indicate that it can hold any typelet various = [ true false 42 'Nushell' ] $various | describe # =>list<any>