Description
First off, thank you @raycharius for building such an insanely useful library. Can't imagine life without it!
I'm running into a type error when I'm attempting to render a conditional within a conditional. Here's a minimal reproduction:
import { HomeTab, Section, setIfTruthy } from 'slack-block-builder'
const arrayOfNumbers = [1, 2, 3]
export const ParentBlocks = () =>
HomeTab().blocks(
Section().text('Hello world'),
setIfTruthy(true, ChildBlocks())
)
const ChildBlocks = () => [
Section().text('This is a child.'),
setIfTruthy(
true,
arrayOfNumbers.map((number) => Section().text(number.toString()))
),
]
The error I'm getting is on the setIfTruthy(true, ChildBlocks())
call, and it reads Type 'SectionBuilder[]' is not assignable to type 'Undefinable<ViewBlockBuilder>'.
.
The issue seems to stem from the fact that the setIfTruthy
conditional in ChildBlocks
is returning an array of blocks.
If I update ChildBlocks
to return one block instead, it works:
const ChildBlocks = () => [
Section().text('This is a child.'),
setIfTruthy(true, Section().text('This works')),
]
I've attempted wrapping the array in a BlockCollection
, but that doesn't work, I believe because BlocksCollection builds its blocks.
Any tips on how to solve or work around this issue would be very much appreciated!