rfcs/docs/types-library-optional.md
witchiest 97e3a0d22f
dot
2025-04-11 08:05:12 -04:00

704 B

types.optional

Summary

This RFC proposes adding a new method to the types library in type functions, that provides a shorthand for types.unionof(type, types.singleton(nil)).

Motivation

Currently its annoying to have to always type types.unionof(meow, types.singleton(nil)) to make a optional type, this leads to having the following appear in codebases that make use of optional types a lot in type functions:

type function optional(type)
	return types.unionof(type, types.singleton(nil))
end

Design

As a solution, a new method to the types library should be added called optional. This new method will act the same as types.unionof(type, types.singleton(nil)).