Skip to content

Fix shorthand property assignment type resolution #646

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

Merged

Conversation

auvred
Copy link
Contributor

@auvred auvred commented Mar 17, 2025

If you try to call getTypeOfSymbol on foo (shorthand property assignment), error type will be returned.

const foo = 1

const res = { foo }
//            ^^^

On line 11973 in checker.ts, declaration.name (not just declaration) is passed to checkExpressionForMutableLocation

    function getTypeOfVariableOrParameterOrPropertyWorker(symbol: Symbol): Type {
        // ...
        else if (isShorthandPropertyAssignment(declaration)) {
            type = tryGetTypeFromEffectiveTypeNode(declaration) || checkExpressionForMutableLocation(declaration.name, CheckMode.Normal);
        }
        // ...
    }

@auvred
Copy link
Contributor Author

auvred commented Mar 17, 2025

@microsoft-github-policy-service agree

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

Great catch, thank you!

@jakebailey jakebailey added this pull request to the merge queue Mar 17, 2025
Merged via the queue into microsoft:main with commit 4389109 Mar 17, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants