Skip to content

Intersection with a mapped type breaks bypassing private assignability. #61743

Open
@miguel-leon

Description

@miguel-leon

πŸ”Ž Search Terms

private assignability intersection mapped type

πŸ•— Version & Regression Information

Latest as of today.

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/CYUwxgNghgTiAEkoGdnwBrwN4CgCQADjAJYBuUALglAFzwB2ArgLYBGIMA3Pq3chSXoBzbgF8cOCgE8CCAJrwAvNni0GLdjHij4AMhW94-QUO3dps+AC0l8AArEwAawA8WVXSZsO2gDTwAcigAgD49Az4BYmEzCVAkOHgIEAp4AA86dG546ETk1Kk6OWzwXIR8+AAvOituHDTbKVU0BX0s+ttK5utw9qA

πŸ’» 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Help WantedYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some cases

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions