I'm not sure why you would need to specify an object's type at the place where it is called, you would usually do that in the function definition.
In the case where you are calling an outside function that accepts any - and because it's someone else's code you cannot change the function's signature - you can define your object with a type declaration first and then pass it into the function.
// if obj does not have the right shape to be a MyMessageType then the error will display here
const obj: MyMessageType = {
foo: 1,
bar: 2,
}
aMessageChannel.port1.postMessage(obj);