Microsoft/TypeScript
在 GitHub 查看Intersection with a mapped type breaks bypassing private assignability.
Open
#61,743 建立於 2025年5月21日
Domain: IntersectionHelp WantedPossible Improvement
倉庫指標
- Star
- (48,455 star)
- PR 合併指標
- (平均合併 6天 17小時) (30 天內合併 9 個 PR)
描述
🔎 Search Terms
private assignability intersection mapped type
🕗 Version & Regression Information
Latest as of today.
⏯ Playground Link
💻 Code
Given
declare class X {
private a: number;
b: string;
}
You're allowed to do:
type Y = { a: number } & { b: string };
declare let y: Y;
let x: X = y as Y & X;
But fails with:
type Z = Pick<{ a: number }, 'a'> & { b: string };
declare let z: Z;
let x: X = z as Z & X;
🙁 Actual behavior
X bypasses private assignability, but the identical type Y errors.
🙂 Expected behavior
Either neither type is allowed to bypass private assignability, or both types are, since they're identical.
Additional information about the issue
No response