Closed
Description
TypeScript Version: 2.6.1
Code
interface A {
first: string;
bList?: B[];
}
interface B {
second: string;
c?: C;
}
interface C {
third: string;
}
const Q: A & { bList: (B & { c: C })[] } = {
first: 'first',
bList: [
{
second: 'second',
c: {
third: 'third',
},
},
],
};
Q.bList.map(item => {
P(item);
});
function P(value: B & { c: C }) {
console.log(value);
}
Expected behavior:
Until 2.5.1 this code did not generate a compilation error.
The type of bList is calculated as follows:
(undefined & (B & {
c: C;
})[]) | (B[] & (B & {
c: C;
})[])
And type of item
B & {
c: C;
}
Actual behavior:
With 2.6.x, this code causes an error.
The type of bList is calculated as follows:
B[] & (B & {
c: C[];
})[]
And type of item
B
The type of item is treated as B and an error occurs. Is this change specified in the changelog?