Is it possible to restrict param
not to accept strings, arrays etc.?
interface foo {
a?: number;
b?: string;
}
function baz(param: foo) {
}
baz("hello");
You can do something like this to make baz
accept at least an object:
interface foo {
a?: number;
b?: string;
}
interface notAnArray {
forEach?: void
}
type fooType = foo & object & notAnArray;
function baz(param: fooType) {
}
baz("hello"); // Throws error
baz([]); // Throws error
fooType
here is an Intersection Type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With