I am seeking to create a function that ensures an object adheres to the type {[key: string]: T} and outputs an object literal based on the input argument.
For instance, let's say I have the following type A:
interface A{
a: string,
b: number
}
I want to define a function B
that accepts an object with properties that all match type A
, and returns the same object with accessible properties using dot notation.
Currently, my function looks like this:
const B = (arg: {[key: string]: A}) => arg;
However, when I use it like this:
const c = B({
a: {
a: "test",
b: 1
}
})
I am unable to access the property a
using dot notation, such as c.a
.
Is there a way to modify function B so that it returns a literal type based on its input parameter, allowing me to access properties with dot notation?