Skip to content

Types ​

Chute is strongly typed. Every variable, parameter, and return value has a type that's checked at compile time. If the types don't match, you get an error before your shortcut is ever built.

Primitive types ​

TypeDescriptionExamples
TextA string of characters"Hello", "${name}"
NumberAn integer or decimal number42, 3.14, -7
BooleanA true or false valuetrue, false

Collection types ​

List<T> ​

An ordered collection of values of type T.

text
const numbers: List<Number> = [1, 2, 3];
const names: List<Text> = ["Alice", "Bob"];
const empty: List<Number> = [];

Dictionary ​

A key-value collection. Keys are always strings.

text
const person = {"name": "Alice", "age": 30};
const empty = {:};

Access dictionary values with dot notation or subscripts:

text
const name = person.name;
const age = person["age"];

Optional types ​

Append ? to any type to make it optional, meaning it can hold either a value of that type or nil.

text
const score: Number? = nil;
const name: Text? = "Alice";

nil ​

The nil literal represents the absence of a value. You can only assign it to optional types:

text
const x: Number? = nil;  // ok
const y: Number = nil;   // compile error

Nil coalescing (??) ​

Use ?? to unwrap an optional with a fallback value:

text
const score: Number? = nil;
const display = score ?? 0; // display is Number, not Number?

The left side must be optional, and the right side must match the inner type.

Nil narrowing ​

Inside an if block that checks for nil, Chute narrows the type automatically:

text
const x: Number? = nil;
if (x != nil) {
  const y = x + 1; // x is Number here, not Number?
}

This also works in the else branch of == nil checks.

Quantity types ​

Chute has built-in quantity types for physical measurements. These map to Shortcuts measurement actions.

text
const duration: Quantity<seconds> = 30;
const distance: Quantity<kilometers> = 5;
const temp: Quantity<celsius> = 22;

Supported units ​

CategoryUnits
Timeseconds, minutes, hours, days, weeks
Lengthmeters, kilometers, miles, feet, inches, yards
Massgrams, kilograms, milligrams, ounces, pounds
Volumeliters, milliliters, gallons, cups, pints, quarts
Temperaturecelsius, fahrenheit, kelvin
Angledegrees

Opaque types ​

These types represent Shortcuts content items. They're returned by stdlib actions and can't be constructed directly.

TypeDescription
DateA date and time
URLA web address
ImageAn image or photo
EmailAn email address
PhoneA phone number
ContactA contact
LocationA street address or coordinate
ArticleA web article
CalendarEventA calendar event
ReminderA reminder
EventAttendeeA calendar event attendee
TimeIntervalA time interval
MediaAudio, video, or GIF content
FileA file or document
RichTextRich text or HTML content
AppAn app
WebPageA Safari web page
ShortcutA shortcut
WeatherWeather conditions
HealthSampleA health data sample
PodcastEpisodeA podcast episode
PodcastShowA podcast show
ShazamMediaA Shazam result
DisplayA display
WindowA window
FocusModeA Focus mode
iTunesProductAn iTunes product
BarcodeA barcode or QR code
MessageA message

Access their properties with dot notation:

text
import Scripting

let d = Scripting.date();
let year = d.year;      // Text
let month = d.month;    // Text

See Expressions for the full property list per type.

Type coercion ​

Use as to convert between types:

text
let n = someText as Number;   // Number?
let d = someText as Date;     // Date?

Coercion returns an optional because the conversion can fail at runtime. The compiler checks that the pair is valid — text as Number works, but boolean as Date is an error.

Type inference ​

You don't always need to write type annotations. Chute infers the type from the value or expression:

text
const name = "Alice";          // inferred as Text
const count = 42;              // inferred as Number
const items = [1, 2, 3];      // inferred as List<Number>
const result = ask("?");          // inferred as Text (from ask's return type)

Type annotations are required when:

  • You're declaring an optional variable with nil (Chute can't infer the inner type from nil alone)
  • You're using dot-name enum shorthand (.red instead of Color.red)