Skip to content
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

Symbol properties should not be exempt from excess property checks in presence of a string index signature #44794

Open
DanielRosenwasser opened this issue Jun 28, 2021 · 4 comments · May be fixed by #58190
Assignees
Labels
Breaking Change Would introduce errors in existing code Bug A bug in TypeScript Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@DanielRosenwasser
Copy link
Member

In #44793, we found that a symbol index signature doesn't turn off excess property checks on symbols; however, a string index signature turns these excess property checks entirely.

interface A {
    a?: string
    b?: number
    [key: string]: unknown
}

const symbolKey = Symbol('key')

const a: A = {
    [symbolKey]: '123', // works!
}

It's likely that some users relied on this behavior; however, those users will be able to use symbol index signatures in TypeScript 4.4.

@andrewbranch
Copy link
Member

Should symbols be exempt from excess property checks in presence of a string index signature?

Nope

@DanielRosenwasser
Copy link
Member Author

Well

It's likely that some users relied on this behavior

and from @ahejlsberg's comment at #44793 (comment)

It's an easy fix, but the odd thing is that it ends up being a breaking change because we previously would validate symbol-named properties again string index signatures when performing excess property checking.

@andrewbranch
Copy link
Member

Well I assumed you’d weigh my “nope” against other opinions and data, but it seems like a good breaking change to me (one I’d vet in 4.5, unless we want to try to backport it into 4.4-beta).

@DanielRosenwasser DanielRosenwasser added Breaking Change Would introduce errors in existing code Bug A bug in TypeScript labels Jun 28, 2021
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 4.5.0 milestone Jun 28, 2021
@DanielRosenwasser
Copy link
Member Author

I would prefer not picking that into 4.4 at this point. My preference is to give people a step-wise upgrade pattern. Ship one version with the string indexer behavior, and then rip off the band-aid in 4.5.

@DanielRosenwasser DanielRosenwasser changed the title Should symbols be exempt from excess property checks in presence of a string index signature? Symbol properties should not be exempt from excess property checks in presence of a string index signature Jun 28, 2021
@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label Dec 15, 2021
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking Change Would introduce errors in existing code Bug A bug in TypeScript Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants