Microsoft/TypeScript
在 GitHub 查看Suspected breaking change with pushing and assigning a 'derived' value into a 'base' array
Open
#59,016 创建于 2024年6月25日
Domain: check: Excess Property CheckingHelp WantedPossible Improvement
仓库指标
- Star
- (48,455 star)
- PR 合并指标
- (平均合并 6天 17小时) (30 天内合并 9 个 PR)
描述
🔎 Search Terms
inline assignment array derived base push 'Object literal may only specific known properties'
🕗 Version & Regression Information
- This changed between versions 4.9.5 and 5.0.4
⏯ Playground Link
💻 Code
interface Base {
id: number;
}
interface Derived extends Base {
name: string;
}
const items: Base[] = [];
let item1: Derived;
let item2: Derived;
item1 = { id: 1, name: 'this is ok regardless' };
items.push(item1);
items.push((item2 = { id: 2, name: 'this is NOT ok in 5.0.4, but is ok in 4.9.5' }));
🙁 Actual behavior
'Object literal may only specific known properties' error
🙂 Expected behavior
The code should not produce an error
Additional information about the issue
It is possible that this is a change to the order in which types are inferred, but I have been unable to find any details in the documentation/changelog.