I'm writing a library and I want to port it to typescript.
Currently it look something like that:
index.js
const is = value => {
... do some returns here
}
is.number = x => typeof x === 'number'
is.bla = x => typeof x === 'bla'
and so on.
I have wrote an interface describing is
and all its methods.
type TypeQueryMethod = (val: any) => boolean;
interface Is {
(val: any): string;
undefined: TypeQueryMethod;
null: TypeQueryMethod;
...
}
When I try to mark is
with the type: const is: Is = value => ...
It throws an error:
Type '(value: any) => string' is not assignable to type 'Is'.
Property 'undefined' is missing in type '(value: any) => string'.
Which makes sense because the declaration of the object is split.
How do you construct such an object that is both a method, and has methods?