TypeDefinition

Overview

A TypeDefinition describes how to validate and cast a string into a given type.
Type definitions can be used in methods that read user text, such as cli.ask(), or File.getContentAs().

You can use one of the classes that have a built-in definition (see list below), or write your own.

More specifically, anywhere a type definition is accepted, you can pass:
  • a class with a type definition
  • a function that accepts a string, returns the cast value, and optionally throws with an error message if the string is not valid
  • an array of type definitions, that will be executed sequentially