Your signature is a bit mixed up. The return type should be T[keyof T] if you intend for the method to return an enum value. The type of the str param should also be keyof T to prevent you from passing invalid strings in, but this will limit you to passing string literals in (or well-typed variables of type keyof T, but not string):
function stringToEnum<T>(enumObj: T, str: keyof T): T[keyof T]
Then either don't specify the type param and let the compiler infer the type correctly:
// type: Foo
// value: 0
const result = stringToEnum(MyEnum, 'Foo');
Or you need to provide typeof MyEnum as the type param:
// type: Foo
// value: 0
const result = stringToEnum<typeof MyEnum>(MyEnum, 'Foo');
If you really want to be able to pass in any arbitrary string enum name, then the return type is a lie: should be T[keyof T] | undefined. You'll also run into trouble when attempting enumObj[str] if the type of str is string and you have noImplicitAny compiler option enabled.
There's a bit more to making generic functions that work with enum types properly, especially numeric enums that have reverse lookup entries at run-time. Take a look at the source code for ts-enum-util (github, npm) for inspiration