Closed littensy closed 1 year ago
There's another problem with this, though! While it allows omitting cases, it still displays an error if the component is nullable:
local function show<T>(source: () -> boolean, component: () -> T, fallback: (() -> T)?)
return switch(source) {
[true] = component,
[false] = fallback,
-- ^^^^^^^^
-- 🔴 Type '(() -> T)?' could not be converted into '() -> T'
}
end
I'm not sure how to cover this case as well. If this decision is intentional, feel free to close this! The original issue might be better to report as a Luau bug.
The current behavior is likely the best option. It's definitely worth looking into as a Luau bug, though.
Currently, the following erroneous code does not produce a type error:
This is caused by differences in behavior between
Map<T, ((() -> U)?)>
andMap<T, () -> U>
. This issue was resolved by replacing the former with the latter.