Package Exports
- @rbxts/variant
- @rbxts/variant/out/init.lua
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rbxts/variant) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Variant (for Roblox) [WIP]
This is a roblox typescript variant (heh, pun) of Variant. See the Variant documentation on how to use Variant.
Over time features may be added from the original library, and roblox-specific features may be added.
Example usage
import { variantModule } from "@rbxts/variant";
export const Animal = variantModule({
dog: fields<{name: string, favoriteBall?: string}>(),
cat: fields<{name: string, furnitureDamaged: number}>(),
snake: (name: string, pattern = 'striped') => ({name, pattern}),
});
const aDog = Animal.dog({name: "Wally"}); // will result in a discriminate value of { type: "dog", name: "Wally" }
const aCat = Animal.cat({name: "Whiskers", furnitureDamaged: true}); // will result in a discriminate value of { type: "cat", name: "Whiskers", furnitureDamaged: true }Supports
Functions
-
cast -
isOfVariant -
keys -
keymap -
lookup -
match -
matchElse -
narrow -
outputTypes -
partialLookup -
partialMatch
Variant Creation
-
variant -
fields -
payload -
variantFactory -
variantList -
variantModule
Types
-
Flags<T> -
Handler<T> -
KeysOf<T> -
Lookup<T, U> -
Matrix<T> -
TypeNames<T> -
VariantCreator<T, F, K?> -
VariantModule<K> -
VariantOf<T> -
TypeExt<K, T> -
WithProperty<K, T>
TODO:
- Luau Coverage/unit testing (using Luau-CLI)