Back to Luau

Type Functions

types-type-functions.md

latest1.6 KB
Original Source

Type Functions

Type functions are functions that run during analysis time and operate on types, instead of runtime values. They can use the types library to transform existing types or create new ones.

Here’s a simplified implementation of the builtin type function keyof. It takes a table type and returns its property names as a union of singletons.

Embedded content

Type function environment

Section titled “Type function environment”

In addition to the types library, type functions have access to:

  • assert, error, print
  • next, ipairs, pairs
  • select, unpack
  • getmetatable, setmetatable
  • rawget, rawset, rawlen, raweq
  • tonumber, tostring
  • type, typeof
  • math library
  • table library
  • string library
  • bit32 library
  • utf8 library
  • buffer library