-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Empty object type is not working #47486
Comments
|
Hmm, how is const a: IEmptyObject = 1; And it's banned by ts-eslint:
|
Well, it seemed like the intent was for the default type to be "empty object" for which Maybe |
|
Thx for your comments guys. I guess that all of us can agree that there's no way to represent an object with no properties and that's a bug, since {a:1} which means "one more property than none" does warn when using the wrong property. The debate on which option is closer to an empty object is important, but might deflect the focus from the real problem that needs fixing... |
Well, no. TypeScript intentionally has structural subtyping. The scenario of needing to be given an exactly empty object seems like the XY problem here. Do you mean to just write |
If you mean accessing the wrong property: this is true of If TS had exact types (#12936), you could represent a truly empty object with |
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow or the TypeScript Discord community. |
Hey guys, thank you for your answers. I have no problem of course with structural subtyping, I just wanted to get warned when accessing a property that was not defined on the object, which in my case needed to be empty. The How would you change ES-Lint's warning? |
@Asaf-S If you want to change the default error message, you can open a request in their repo: https://github.com/typescript-eslint/typescript-eslint and ask for their opinions about making the error message less confusing/ambiguous. If you just want to change the message for yourself or unban it, you can use the rule's option: https://typescript-eslint.io/rules/ban-types#options |
Someone needs to let the ESLint team know that being able to assign primitives to const x: { toString(): string } = 42; The only thing unique about |
I assume it's for the sake of "common mistakes". People are far more likely to write The problem with |
Bug Report
π Search Terms
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
I wrapped the
Request
type of theExpress
library, in order to change the default value of theRequest.params
property.If I would give a non-empty type, then it works:
π Expected behavior
I should have been warned.
The text was updated successfully, but these errors were encountered: