My goal is for my function to return a nested type of Content, but it's not working even though the type that should be returned is known. Let's take a look at an example:
type Content = {
some: {
extra: string;
prop: number;
},
other: string,
somenumber: number
}
const factory = (content: Content) => {
return (key: keyof Content) => {
return content[key];
};
};
const content:Content = {
some: {
extra: "wow",
prop: 123
},
other: "abc",
somenumber: 999
};
const el = factory(content);
const some = el("some"); // this works fine, I can pass an existing key as a string
console.log(some.extra); // however, I'm unable to access "extra"
I anticipate that "some" should include both "extra" and "prop," but trying to access "extra" results in a TypeScript error.