Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
  • Language Reference Guide
    • Readme
    • Types in the Nu Language
      • Basic Types
        • Any
        • Boolean
        • Integer
        • Float
        • Filesize
        • Duration
        • Datetime
        • Range
        • String
        • Record
        • List
        • Table
        • Closure
        • Nothing
        • Binary
        • Glob
        • Cell-Path
      • Other Data Types

        • Types that cannot be used to declare variables
          • Path
        • Types which are not declarable
          • Error
          • CustomValue
          • Block
      • Type signatures
      • Commands that interact with types
    • Operators
    • Flow control
      • if/else
      • loop
      • while
      • match
      • try/catch
      • break
      • return
      • continue
    • Filters
      • each and par-each
      • Filters to select subsets of data
      • where and filter
      • Understanding the difference between get and select
    • Custom Commands
    • Declarations
    • Variable Scope
    • Strings and Text Formatting
    • Helpers and debugging commands
    • Pipelines
    • MIME Types for Nushell

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

  1. A variable defined as any takes on the type of its currently assigned value. In other words, describe will never return the any type itself. See the examples below.

  2. 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
  3. Annotate a list to indicate that it can hold any type

    let various = [ true false 42 'Nushell' ]
    $various | describe
    # =>list<any>
Edit this page on GitHub
Contributors: NotTheDr01ds, fdncred
Next
Boolean