Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[ban-types] banning 'object' in 3.0.0 discussion #2068

Closed
Labels
package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginwontfixThis will not be worked on
@daviduzumeri

Description

@daviduzumeri

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.0ban-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 ofRecord<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 loveRecord -- 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp