Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()
}

Any idea what type I should 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)

Thanks in advance

like image 450
danday74 Avatar asked Nov 16 '20 04:11

danday74


1 Answers

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.

like image 180
Evert Avatar answered Sep 19 '22 01:09

Evert