#Extended interface inside function argument
23 messages · Page 1 of 1 (latest)
no, what are you trying to do exactly?
options: BaseOptions lets you pass anything extending BaseOptions just fine.
what are you trying to do though?
I dont want to declare an interface for opts
you don't need to
you could just intersect it into a new type, BaseOptions & { collection?: string; id: string }
it'll make documentation kinda worse though since those other props aren't documented
oh damn i didnt know that's possible
You can use generics in objects, but usually they should be inferable from the structure of the object.
The classic example of a "misused generic" is a function like:
function getMeA<T>(): T {
/* magic */
}
Since the generic has no relation to anything in the call signature, it can't be inferred and also there's no way to actually implement that function safely: it's not really a generic, it's a type-cast that's pretending to be a generic.
How can I resolve that?
well, not using that pattern
if you can't specify the result type statically, it's generally safer to have it be a broader type then specifically assert it where it's known
this doesn't really matter, it's more about what the function declares.
I don't get it
one step further but still
i prefer it be the entire thing