My defined mapped type looks like this:
type FooOrBar = "foo" | "bar"
type ObjectWithHi<T extends FooOrBar> = {
[key in T]: 'hi';
}
I am trying to create a function call that follows this structure:
getFooOrBar<'foo'>('foo')
The function I have attempted to define is as follows:
function getFooOrBar<T extends FooOrBar>(fooOrBar: T): ObjectWithHi<T> {
return {
[fooOrBar]: 'hi',
}
}
Unfortunately, TypeScript gives me an error saying:
Type '{ [x: string]: string; }' is not assignable to type 'ObjectWithHi<T>'.
What might be the issue here?