How do I type an arrow function with a parameter that has a default value?
before in javascript, it is a function that accepts a boolean value and when it is not provided it defaults to false
const foo = (initial = false) =>
now I rewrote this function into TS and expand the param to be able to get a function that returns a boolean,
const foo = <T extends boolean>(initial: T | (() => T)) =>
Now the problem is that I still need to make initial
default to false
when it is not provided. How can I do that in TS? I tried a few but it doesn't pass the TS compiler.
For example
const foo = <T extends boolean>(initial = false: T | (() => T)) =>
will be a syntax error in TS