microsoft / microsoft/TypeScript
Type infer issue in interfaces with internal properties
Open
@rbuckton is already working on this.
Since Feb 10, 2021.
Rescheduled
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Bug Report
🕗 Version & Regression Information
4.1.3 & 4.2.0-dev the same
⏯ Playground Link
💻 Code
interface Base {
inside: {
v: number;
}
}
interface X extends Base {
inside: {
v: 1
}
a: number;
x?: number;
}
interface Y extends Base {
inside: {
v: 2
}
a: number;
y?: number;
}
interface Z extends Base {
inside: {
v: 3
}
z?: number;
}
const v2: number = 2;
let v1: 1|2;
if (v2 === 2) v1 = 2; else v1 = 1;
const value: X | Y = {
inside: {
v: v1
},
a: 10
};
console.log(value);
🙁 Actual behavior
Type '{ inside: { v: 1 | 2; }; a: number; }' is not assignable to type 'X | Y'.
Type '{ inside: { v: 1 | 2; }; a: number; }' is not assignable to type 'Y'.
Types of property 'inside' are incompatible.
Type '{ v: 1 | 2; }' is not assignable to type '{ v: 2; }'.(2322)
🙂 Expected behavior
No error ^^
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.