Closed kaatt closed 4 years ago
@issuehunt has funded $40.00 to this issue.
Hi!
I can't seem to re-create the error.
import ow from './dist/source'
interface Options {
foo?: (baz: number) => string
bar: (baz: number) => string
baz?: number
}
function test(options: Options): any {
const { foo, bar, baz } = options
ow(bar, ow.function)
ow(foo, ow.optional.function)
ow(baz, ow.optional.number)
}
const o1 = {
bar: (x) => 'asd',
baz: 2,
};
test(o1);
The above code doesn't throw any errors for me.
Maybe your options object that you pass to test
doesn't look like this, so that's maybe where I'm wrong
@kaatt It happens because you're using strictNullChecks
, I will open a PR with a possible fix.
After some more digging, I realized it's somewhat the expected behaviour.
But you can use the non-null assertion operator. (!
)
- ow(foo, ow.optional.function) // throws TS2345
+ ow(foo!, ow.optional.function)
I've fixed the issue by approaching it in the other direction, which seems to work well - tests are all still passing.
@sindresorhus has rewarded $36.00 to @theguardianwolf. See it on IssueHunt
The above code throws this error:
Not sure what's wrong here. Is it a bug with
ow
's typings?This workaround works:
IssueHunt Summary
#### [ theguardianwolf](https://issuehunt.io/u/theguardianwolf) has been rewarded. ### Backers (Total: $40.00) - [ issuehunt](https://issuehunt.io/u/issuehunt) ($40.00) ### Submitted pull Requests - [#184 Allow potentially undefined functions to be checked](https://issuehunt.io/r/sindresorhus/ow/pull/184) --- ### Tips - Checkout the [Issuehunt explorer](https://issuehunt.io/r/sindresorhus/ow/) to discover more funded issues. - Need some help from other developers? [Add your repositories](https://issuehunt.io/r/new) on IssueHunt to raise funds.