I'm trying to build a constructor which allows you to pick the name of one key:
function func<T>(arg: T, name: string) {
return {
[name]: arg,
foo: true,
bar: '...',
baz: 23
}
}
const { hey } = func('yo', 'hey');
As you can see in this REPL, the resulting custom property's type get's mixed up with all the other types in the result object, i.e. it's string | number | boolean.
Why does this happen? How can I avoid the issue?