here is the short example of what I am trying to achieve
type Arg = {
name: string
}
function fun(arg: Arg): // what do I return ?
function fun (arg) {
return {[arg.name]: true}
}
is there anything I can do about this?
here is the short example of what I am trying to achieve
type Arg = {
name: string
}
function fun(arg: Arg): // what do I return ?
function fun (arg) {
return {[arg.name]: true}
}
is there anything I can do about this?
I think you are looking for smth like this:
type Arg<T extends string> = {
name: T
}
function fun<Name extends string, T extends Arg<Name>>(arg: T): Record<T['name'], boolean>
function fun<Name extends string, T extends Arg<Name>>(arg: T) {
return { [arg.name]: true }
}
const result = fun({ name: 'John' }) // Record<"John", boolean>
More about infering function arguments, you can find in my article