Sorbet

Sorbet

  • Get started
  • Docs
  • Try
  • Community
  • GitHub
  • Blog

›Type System

Getting Started

  • Overview
  • Adopting Sorbet
  • Tracking Adoption
  • Quick Reference
  • Visual Studio Code
  • TypeScript ↔ Sorbet

Static & Runtime

  • Gradual Type Checking
  • Enabling Static Checks
  • Enabling Runtime Checks
  • RBI Files
  • Command Line Reference
  • Runtime Configuration

Troubleshooting

  • Troubleshooting
  • Why type annotations?
  • FAQ
  • Error Reference

Type System

  • sig
  • Type Annotations (non-sig)
  • T.let, T.cast, T.must, T.bind
  • Class Types (Integer, String)
  • Arrays & Hashes
  • Nilable Types (T.nilable)
  • Union Types (T.any)
  • Flow-Sensitivity (is_a?, nil?)
  • T.type_alias
  • Exhaustiveness (T.absurd)
  • T::Struct
  • T::Enum
  • T.untyped
  • Blocks, Procs, & Lambdas
  • Abstract Classes & Interfaces
  • Final Methods & Classes
  • Override Checking
  • Sealed Classes
  • T.class_of
  • T.self_type
  • T.noreturn
  • T.attached_class
  • Intersection Types (T.all)
  • T::NonForcingConstants

Experimental Features

  • Tuples
  • Shapes
  • Generics
  • Requiring Ancestors
Edit

T.noreturn

TODO: This page is still a fragment. Contributions welcome!

T.noreturn

This indicates that a method never returns. Some examples of things that never return are: infinite loops, exiting the program, and raising exceptions.

This powers dead code analysis. If you try to do something with a value of type T.noreturn, you will get an unreachable code error.

# typed: true
extend T::Sig

sig {returns(T.noreturn)}
def loop_forever
  loop {}
end

sig {returns(T.noreturn)}
def exit_program
  exit
end

sig {returns(T.noreturn)}
def raise_always
  raise RuntimeError
end

x = exit_program
puts x # error: This code is unreachable

T.noreturn is a subtype of every type, but no type except T.noreturn (trivially) and T.untyped is a subtype of T.noreturn.

← T.self_typeT.attached_class →

© 2022 Stripe · Get started · Docs · Try · Community · Blog · Twitter