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

Elementwise elaboration fails to be found for properties mixed with incompatible index signatures using intersections #58344

Open
Andarist opened this issue Apr 28, 2024 · 0 comments
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone

Comments

@Andarist
Copy link
Contributor

πŸ”Ž Search Terms

elementwise elaboration errors write type index signature intersection

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.5.0-dev.20240428#code/MYewdgzgLgBFCm0BcMDeMDaBrF0BOAlmAOYC6KYArgLYBG8eMAvjAGRowBmIIuUhJZjAC8HbrxgAiWgEM8k5gG4AUEA

πŸ’» Code

const test: { [k: string]: number } & { foo: string } = { foo: "bar" };

πŸ™ Actual behavior

test variable gets highlighted

πŸ™‚ Expected behavior

I'd expect foo property in the source to get highlighted

Additional information about the issue

I don't really expect this to get any meaningful priority ;p it's just something interesting that I noticed while investigating some legitimate question as to why an error is not on the property itself in a more complex situation. Such intersections are flawed on principle so πŸ€·β€β™‚οΈ

This happens because elaborateElementwise uses getBestMatchIndexedAccessTypeOrUndefined and that prefers concrete properties on intersections over index signatures. The problem is that you can read such dubious properties from the type (and it has a matching type in the example above so it doesn't become an elementwise candidate) but you can't quite write to them.

@RyanCavanaugh RyanCavanaugh added Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases labels May 1, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Projects
None yet
Development

No branches or pull requests

2 participants