I have function using an object as parameter like this:
interface Options {
foo?: string;
bar?: number;
};
function fooNction(opts: Options): void {
}
This works fine in some cases but not all:
fooNction({foo: "s"}); // OK
fooNction({a: "x"}); // fine as TS gives an Error as expected
fooNction("hello"); // no Error...
I tried to extend my interface from TS 2.2 object type like this
interface Options extends object {
foo?: string;
bar?: number;
};
to disallow basic types but typescript tells "Cannot fine name 'object'".
Is there any way to define an interfaces has to be an object but has no mandatory field?