Skip to content

Do not set valueDeclaration for intersection properties when one symbol does not have a valueDeclaration #61872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mdm317
Copy link

@mdm317 mdm317 commented Jun 15, 2025

Fixes #61743
This issue arised because the intersection types are different.

declare class X {
	private a: number;
	b: string;
}
type Y = { a: number } & { b: string };
type Z = Pick<{ a: number }, 'a'> & { b: string };
type T1 = X & Y // T1 is never
type T2 = X & Z // but T2 is not never

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Jun 15, 2025
@@ -15547,7 +15547,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
let firstValueDeclaration: Declaration | undefined;
let hasNonUniformValueDeclaration = false;
for (const prop of props) {
if (!firstValueDeclaration) {
if(!prop.valueDeclaration){
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In isConflictingPrivateProperty, if symbols are not uniform and has private properties, determine property is conflict

    function isConflictingPrivateProperty(prop: Symbol) {
        // Return true for a synthetic property with multiple declarations, at least one of which is private.
        return !prop.valueDeclaration && !!(getCheckFlags(prop) & CheckFlags.ContainsPrivate);
    }

Currently, a intersection/uniform property is treated as uniform when one source property has a valueDeclaration, while another source property(mapped type) does not.
I think we should treat such properties as non-uniform instead.

@mdm317
Copy link
Author

mdm317 commented Jun 15, 2025

@microsoft-github-policy-service agree

@mdm317 mdm317 marked this pull request as ready for review June 15, 2025 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Intersection with a mapped type breaks bypassing private assignability.
2 participants