In Rust is possible to omit a type parameter using _
, which infers the concrete type. Is there any way of doing the same in TypeScript? So for example, I have this now, but I want to omit the first type parameter in open()
(see second snippet).
(This open
is supposed to be the same as MatDialog.open
in Angular)
// -----
// TYPES
// -----
interface Params<T> {
data: T;
}
function open<T, D = any>(component: ComponentType<T>, params: Params<D>) {
// ...
}
// -----
// USAGE
// -----
interface MyComponentData {
foo: number;
}
open<MyComponent, MyComponentData>(MyComponent, {
data: {
foo: 42,
},
})
The real question, is it possible to omit T
so it's inferred from the usage? For example, using something like _
as placeholder (which doesn't work):
open<_, MyComponentData>(MyComponent, {
data: {
foo: 42,
},
})