sindresorhus/ow






The issue has been solved
TypeScript optional function argument throws error TS2345 with `ow.optional.function` #147
kaatt posted onGitHub
interface Options {
foo?: (baz: number) => string
bar: (baz: number) => string
baz?: number
}
function func1(options: Options): any {
const { foo, bar, baz } = options
ow(bar, ow.function)
ow(foo, ow.optional.function) // throws TS2345
ow(baz, ow.optional.number) // doesn't throw
}
The above code throws this error:
src/test.ts:11:11 - error TS2345: Argument of type 'Predicate<Function>' is not assignable to parameter of type 'BasePredicate<((baz: number) => string) | undefined>'.
Types of property '[testSymbol]' are incompatible.
Type '(value: Function, main: Main, label: TimerHandler) => void' is not assignable to type '(value: ((baz: number) => string) | undefined, main: Main, label: TimerHandler) => void'.
Types of parameters 'value' and 'value' are incompatible.
Type '((baz: number) => string) | undefined' is not assignable to type 'Function'.
Type 'undefined' is not assignable to type 'Function'.
11 ow(foo, ow.optional.function)
~~~~~~~~~~~~~~~~~~~~
Not sure what's wrong here. Is it a bug with ow
's typings?
This workaround works:
if (foo) ow(foo, ow.function)