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.
The linter warns against the lowercase
object
type for the reason that the type was tricky to use. With improvements to thein
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 ofobject
below helps catch a typo which might have been overlooked if the parameter type wasRecord<string, unknown>
.typescript-eslint removed
object
from the ban list for 5.0.0, and has been suggesting usingobject
since 5.46.0.