Search code examples
typescripteslinttslint

Don't use object as a type


I am getting the lint error:

don't use object as a type

When I use object as a type, example follows:

export const myFunc = (obj: object): string => {
  return obj.toString()
}

What type should I give to an object with unknown properties?

If it helps the object in question is NOT an array (which I know is strictly an object in JS).


Solution

  • There's a few different ways to do this. Generally I feel the need for this is a bit of an anti-pattern.

    But I would probably go for Record<string, any>, if that covers it for you.