Example Code on Array Docs Gives a Warning
Closed this issue · 2 comments
Link: https://mobily.github.io/ts-belt/api/array
node: v18.2.0
typescript: 4.7.3
tsserver: 0.11.1
tsconfig.json: i follow this https://mobily.github.io/ts-belt/docs/getting-started/config
I just tried the code from the array doc and it gives a warning like this:
the code runs fine, but the warning annoys me. So i removed the warning by handling the Option
using match
:
import { A, O, pipe } from "@mobily/ts-belt";
const arr = A.makeWithIndex(5, (i) => i); // if i changed this to [] without O.match, it will throws error
console.log(
pipe(
arr,
A.tail,
O.match( // initially i wanna use O.getWithDefault([]), but it also gives warning. O.getExn works but throws error if arr = [] :(
(tail: readonly number[]) => tail,
() => []
),
A.take(2),
A.map((val) => val * 2)
)
);
question: is it some secret pipe
behavior that handles Option
or A.take
type is not complete or the doc needs an update?
thank you
i just removed the Option handling and change A.tail
to A.tailOrEmpty
and the code runs fine and no warning. So, i propose that the docs should use A.tailOrEmpty
because it returns Array<A>
instead of Option<Array<A>>
@ahmaddynugroho thanks, good catch! 👀 (fixed)