-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[ban-types] banning 'object' in 3.0.0 discussion #2068
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
Comments
We build the recommended set and default rule configs for the majority of users, not just power users. Most users will not want to use it. For the most part it's a bad type to use because it's nigh impossible to use due to microsoft/TypeScript#21732. I do recognise that there are perfectly valid use cases for For example;
The vast majority of our users fall into the latter category - they are working at some company building out a product such as a website. If you fall into the first category, then you can reconfigure the rule as appropriate. |
OK -- that lines up with my understanding, at least; if our usecase of needing it as a base for a generic is really that specific in the grand scheme of things, I'm happy to run with that, I just wanted to make sure I wasn't fundamentally misunderstanding the situation. If users really are running into trying to use it as an actual object type when writing business logic, then yeah, Record is obviously a superior alternative. You've obviously got more of the data regarding what the acutal in the field use is, so if that's the case that makes perfect sense and maybe we'll even benefit by having to limit use of |
Definitely - if But without that, But I still recommend |
Oh yeah, |
@daviduzumeri for what it's worth, I'm with you. |
#2137 was released with the latest version which will allow you to specifically turn off the ban on just |
So I've gone through the pull request that introduces it and the discussion therein -- and apologies in advance if I'm just whipping a dead horse everybody would prefer to stay dead -- but the recent 3.0.0
ban-types
update's banning ofobject
seems particularly ill-advised to me for a couple of reasons. We here at TouchBistro have our own custom lint ruleset so we can always just disable it, but I wanted to at least broach the subject in the general community about the specific usecases whereobject
is useful because, well, there's always the possibility that I'm wrong.In short, the recommended replacement of
Record<string, unknown>
doesn't, I think, generally replace what we useobject
for -- or, I suspect, what the vast majority of developers use it for. If there's another type that can be used as an extension base for generics to hard-lock that specific type as anobject
, I'd love to hear it, butRecord<string, unknown>
can't be used in this case because casting any ole' object type to that requires an index property, which adds a lot of complexity to the typing just to make lint rules pass. There's a larger discussion here about how perhaps TypeScript should make index properties default for keys of objects or provide greater flexibility for type refinement when interacting withobject
, but at the end of the day I don't think creating types with properties that are objects is all that rare -- take, for example, a database model with ajsonb
column, where the format of what's in that column can change, SoModel<T extends object> { name: string, id: number, blob: T }
allows for sub-typing of that model. The argument is made that this is a niche case, but is it really that niche? If it is, then I'll totally take the L on this one and acknowledge that we just have different needs in the ruleset, but unlikeObject
orFunction
, there are perfectly cromulent uses ofobject
that, while maybe a bit advanced, certainly don't take it out of the realm of acceptable idiomatic TypeScript -- and moreso, I'd argue that even MORE niche are the cases where it can be acceptably replaced with an unsealed indexed type such asRecord<string, unknown>
.Look, I love
Record
-- there are tons of situations where it's a wonderful tool, especially when performing diffs or other in-the-guts object-level wizardry or whatever -- I'm not knockingRecord
. And I recognize that the goal of the lint ruleset is to keep dangerous tools out of the hands of developers who might not realize their implications. Butobject
isn't a handgun, it's at best a Swiss Army pen knife, and I'm not sure putting rubber on it and suggesting a nail file instead is the proper risk/reward calculus.The text was updated successfully, but these errors were encountered: