1

I am new to TypeScript, normally we can do somethin like this:

interface IPerson {
    name: string,
    age: number
}

const tim:IPerson = {
    name: 'Tim',
    age: 21
}

above codes, "tim" object need to include name(with string value) and age(with number value) properties.

So my question is, can I do the same thing with new Map()? (like the codes above, must include name(name value must be string) and age(age value must be number) properties.)

I did tried creating some generic Interfaces and types but I don't think I am doing it right, because none of the work.

JustANewCoder
  • 347
  • 2
  • 10
  • 1
    TS doesn't have built-in typings for this; you could write them yourself, but it's not clear what advantage this has over a plain object. See [this q/a](https://stackoverflow.com/q/54907009/2887218) for more info; if I use the code in there with your example I get [this playground link](https://tsplay.dev/wXOjoW). – jcalz Feb 14 '23 at 16:58

0 Answers0