-1

Came across a question regarding type interfaces that I cannot understand (unless it's incorrect)

methodName(): <Map<String, String>> {...

Is this return type incorrect and or perhaps meant to be <string, string>?

Ben Racicot
  • 5,332
  • 12
  • 66
  • 130
  • Thanks @jonrsharpe, no, we know what the difference is but the case above is not how I would ever use a primitive's interface. I'd only use `String` when extending the type into a new interface. Never as a return type. – Ben Racicot Sep 09 '21 at 21:50
  • Then please [edit] to clarify what you _are_ asking. Maybe you could include _where_ you came across that. – jonrsharpe Sep 09 '21 at 21:52

1 Answers1

1

The only legitimate case I can think of that you are using the String constructor (for some reason), and you therefore run into the fact that String is not assignable to string.

const str: string = new String('testing123')
// Type 'String' is not assignable to type 'string'.
//   'string' is a primitive, but 'String' is a wrapper object.
//     Prefer using 'string' when possible.(2322)

Playground

All all likelihood, however, this is a mistake. If you change those to string and everything still type checks fine, then it was almost certainly a mistake.

Alex Wayne
  • 178,991
  • 47
  • 309
  • 337