Remember that these interfaces follow the duck set: if an object is like an interface, it corresponds to the interface.
So,
function testB(): IBaseInfo = { return { name: 'Hey!' }; }
exactly matches
function testA(): IBaseInfo = { var result: IMyInfo = { name: 'Hey!' }; return result; }
In any case, the returned object looks like IMyInfo, so this is IMyInfo. Nothing that happens inside a function affects the interfaces that it corresponds to.
However, in your examples, the return value of the function is IBaseInfo, so the compiler and intellisense will assume that the object is only IBaseInfo. if you want the caller to know that the return value is IMyInfo, you need to make the return value of the IMyInfo function:
function testB(): IMyInfo = { return { name: 'Hey!' }; }
or using type inference, just
function testB() = { return { name: 'Hey!' }; }
source share