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

Incorrectly allowing the use of methods that the return value of Object.groupBy does not have #59156

Closed
kurehajime opened this issue Jul 6, 2024 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@kurehajime
Copy link

πŸ”Ž Search Terms

Object.groupBy

πŸ•— Version & Regression Information

I tried with 5.2.2 and 5.6.0-dev.20240705
To see what is happening, you need to add "esnext" to lib.

⏯ Playground Link

https://www.typescriptlang.org/ja/play/?ts=5.6.0-dev.20240705#code/MYewdgzgLgBAhgJwTAvDA2gZgDQwIy4AsuBMArLgJy4BMAugFCiSwgBGAVqjAPKcCmwKADoA5ghABXAA4AhAJ4AKRAlyL+ASlQA+GPxgBSGDVQo0ABhgB+GACJ+AN35hbMAFx2QAEy+2NAbgZ2DmEoEABlKAQASzBRRS0AekSYABUAC31QAFtpaIAbfmQ4fPyQAHcIGCh06IhhGAAJCsci3Br9NglKour07qq4MD0kEARhIM4rUIio2PiklIy6mGgC-JhRaKcqjpguioheoZGJcaA

πŸ’» Code

const arr = [3, 1, 4, 1, 5, 9, 2]
const obj = Object.groupBy(arr, (e) => e % 2 === 0 ? "even" : "odd");
obj.toString() // The compiler allows this. However, the browser throws an error.
obj?.toString() // This still gives the browser an error.

πŸ™ Actual behavior

The value returned by "Object.groupBy" is an object with null as prototype and does not have toString(). However, TypeScript compilers allow this.

πŸ™‚ Expected behavior

If a non-existent method such as toString is used in the value returned by "Object.groupBy", the compiler will detect it.

Additional information about the issue

No response

@kurehajime
Copy link
Author

I noticed this after filing an Issue.
This code is more concise.

const obj = Object.create(null);
obj.toString()

@MartinJohns
Copy link
Contributor

Essentially a duplicate of #1108.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants