ts-callable-object
v1.0.1
Published
```ts import { callableObject } from 'ts-callable-object';
Downloads
1
Readme
ts-callable-object
import { callableObject } from 'ts-callable-object';
const math = callableObject((a: number, b: number) => {
return a + b
}, {
add: (a, b) => a + b,
sub: (a, b) => a - b,
mult: (a, b) => a * b,
div: (a, b) => a / b,
})
math(4, 2) // ts-ok, js-ok, returns 6
math.add(4, 2) // ts-ok, js-ok, returns 6
math.sub(4, 2) // ts-ok, js-ok, returns 2
math.mult(4, 2) // ts-ok, js-ok, returns 8
math.div(4, 2) // ts-ok, js-ok, returns 2
ts-ok means that typescript doesn't throw any errors and provides full type support. js-ok means that the code runs, doesn't throw any runtime exceptions, and returns the expected value.