There's something strange happening with the Typescript compiler when I use an interface in certain cases.
For instance, everything works perfectly fine here with no errors:
interface Bar {
letter: 'a' | 'b';
}
declare class Foo {
constructor(bars: Bar[]);
}
const foo = new Foo([
{
"letter": "a"
},
{
"letter": "b"
}
]);
However, if I mistakenly add an unnecessary parameter like this:
const foo = new Foo([
{
"letter": "a"
},
{
"letter": "b",
"what": 175875,
}
]);
Then, unexpectedly, the compiler throws an error for both instances of letter
:
Type 'string' is not assignable to type '"a" | "b"'.
Am I overlooking something or could this be a bug within the compiler?