Is it possible to infer a generic type of value using types only?
For example the type:
interface MyType<T extends string> {
foo: Record<T, any>,
bar: Record<string, T>
}
You could infer the generic using a function:
function typed<T extends string>(val: MyType<T>) {
return val;
}
// Works! no typescript diagnostics.
typed({
foo: { a: null, b: null },
bar: { whatever: 'a' }
}) // expect MyType<'a'|'b'>
is there a type-only syntax that can be inferred without a function? (and of course without specifying the type argument in the generic)
// Does not work! (Generic type 'MyType<T>' requires 1 type argument(s).)
const myType: MyType = {
foo: { a: null, b: null },
bar: { whatever: 'a' }
}