diff --git a/docs/user-side-subtype-checking-methods.md b/docs/user-side-subtype-checking-methods.md index 446fe95..1c462db 100644 --- a/docs/user-side-subtype-checking-methods.md +++ b/docs/user-side-subtype-checking-methods.md @@ -112,26 +112,52 @@ This RFC proposes adding 4 new methods to the [`type`](./user-defined-type-funct The `only` methods are diffrent with how they validate, as shown below. -Example 1: +### String Enum Examples ```luau type meow = number | "mrrp" | string print(meow:hasonlysubtypeof(types.string)) -- false, because theres a number in the union. print(meow:hassubtypeof(types.string)) -- true, because even though theres a number, theres also types with a subtype of string, and also string itself. -``` -Example 2: -```luau type mrow = "purr" | "meow" print(meow:hasonlysubtypeof(types.string)) -- true, because despite the union being made up of singletons. Those singletons have the subtype of string, so it returns true. print(meow:hassubtypeof(types.string)) -- true ``` +### Tagged Enum Examples +```luau +type CatnipPurity = "90%" | "10%" | "11%" + +type BaseCatnipInfo

= { + purity: P +} + +type TwentyPercentPurityCatnip = { + purity: "20%" + name: "Average Catnip" +} + +print(TwentyPercentPurityCatnip:hasonlysubtypeof(BaseCatnipInfo)) -- false, because "20%" is not an option in the string enum 'CatnipPurity'. +print(TwentyPercentPurityCatnip:hassubtypeof(BaseCatnipInfo)) -- also false for the same reason + +type WeakCatnip = BaseCatnipInfo<"10%"> & { + name: "Weak Catnip" +} + +print(WeakCatnip:hasonlysubtypeof(BaseCatnipInfo)) -- true, because unlike the previous example "10%" is an option in the string enum 'CatnipPurity'. +print(TwentyPercentPurityCatnip:hassubtypeof(BaseCatnipInfo)) -- also true + +type FishyCatnipUnion = WeakCatnip | TwentyPercentPurityCatnip + +print(FishyCatnipUnion:hasonlysubtypeof(BaseCatnipInfo)) -- false, because "20%" is not an option in the string enum 'CatnipPurity'. +print(TwentyPercentPurityCatnip:hassubtypeof(BaseCatnipInfo)) -- true, because atleast one of the components has the subtype of BaseCatnipInfo (WeakCatnip). +``` + ## Drawbacks Adds extra methods to the type userdata in User-Defined type functions. ## Alternatives -Do nothing, and let users write the checks themselves as it is currently. \ No newline at end of file +Do nothing, and let users write the checks themselves as it is currently.