Today we are going to talk about the difference between the
string types in Typescript.
Type error: Type 'String' is not assignable to type 'string'.
Let's take a look at the above error.
To begin, we know that whether we use String or string, we would want to refer to the same thing. But both of those are a little different.
If you check if it's a string or not, you will get *
let name = new String('Mike'); console.log(typeof name); // object
Therefore, when you are creating a function, type or interface in Typescript, it is recommended to use lowercase
string to tell Typescript you want to get an actual string. If you use
String, then you will get an object (which is not what you would want).
Thank you for reading.
Top comments (0)