denoland / deno_lint

Blazing fast linter for JavaScript and TypeScript written in Rust
https://lint.deno.land/
MIT License
1.53k stars 172 forks source link

suggestion: remove `object` from `ban-types` #1159

Closed 0f-0b closed 1 year ago

0f-0b commented 1 year ago

The linter warns against the lowercase object type for the reason that the type was tricky to use. With improvements to the in operator introduced in TypeScript 4.9, this is no longer the case. The suggested alternative, Record<string, unknown>, has its own problems. For example, the use of object below helps catch a typo which might have been overlooked if the parameter type was Record<string, unknown>.

export function fn(obj: object) {
  if ("type" in obj) {
    // @ts-expect-error Property 'tyep' does not exist on type 'object & Record<"type", unknown>'.
    obj.tyep;
  }
}

typescript-eslint removed object from the ban list for 5.0.0, and has been suggesting using object since 5.46.0.