After reading this question or this article, I'm still a bit confused about the subtle differences between an interface and a type.
In this example, my goal is to assign a simple object to a broader Record<string, string> type:
interface MyInterface {
foobar: string;
}
type MyType = {
foobar: string;
}
const exampleInterface: MyInterface = { foobar: 'hello world' };
const exampleType: MyType = { foobar: 'hello world' };
let record: Record<string, string> = {};
record = exampleType; // Compiles
record = exampleInterface; // Index signature is missing
The assignment is possible when declaring my object with a type, but not when declaring a similar one with an interface. It says that the index signature is missing, but to my (limited) understanding of index signatures, none of MyType and MyInterface actually have one.
What is the reason why the last line does not compile whereas the previous one does?