0

I'm a bit new to Typescript and encountered something I haven't seen before on an example I was reading. A collection of data is declared just like this:

tableData: {}[] = [
    {
        name: 'bob',
        job: 'assassin',
        weapons: 'pool noodle, water gun'
    },
    {
        name: 'sally',
        job: 'basketweaver',
        weapons: 'needle, twine'
    },
    {
        name: 'mary',
        job: 'theif',
        weapons: 'smoke bomb, marauders map'
    },
]

What does {}[] mean?

Is this any different than declaring tableData: any[] = [...] ?

Chris Phillips
  • 1,997
  • 2
  • 19
  • 34
  • `{}` is an empty object type, which is different from `unknown` only in that `null` and `undefined` are not assignable to it; and `unknown` is like a type-safe `any` in that all values can be assigned to it (the type-unsafe `any` also allows you to assign values of type `any` to any other type). This example makes me unhappy though; why is it `{}[]` and not `{name: string; job: string; weapons: string}[]` or something more specific? I can expand this into an answer but I think the question might be a duplicate (e.g., "what's the difference between `{}` and `any` and `unknown`?") – jcalz Jul 14 '20 at 03:16
  • Still looking... [this answer](https://stackoverflow.com/a/61648483/2887218) touches these points but it's not a perfect match – jcalz Jul 14 '20 at 03:19
  • Okay, looks like [this question](https://stackoverflow.com/questions/59135229/how-to-undestand-relations-between-types-any-unknown-and-between-them-and-o) is what this duplicates... unless you're asking about the array part. – jcalz Jul 14 '20 at 03:20

0 Answers0