JavaScript has 7 primitive types strings, numbers, booleans, null, undefined, symbol, and bigint
, The first five have been around since the beginning, The symbol primitive was added in ES2015 and bigint is in the process of being finalized.
Primitives are distinguished from objects by being immutable and not having methods. You might object that strings do have methods
console.log('primitive'.charAt(3)) // output is "m"
Well, While a string primitive does not have methods, JavaScript also defines a String object type that does. JavaScript freely converts between these types. When you access a method like charAt on a string primitive, JavaScript wraps it in a String object, calls the method, and then throws the object away.
TypeScript models this distinction by having distinct types for the primitives and their object wrappers:
- string and String
- number and Number
- boolean and Boolean
- symbol and Symbol
- bigint and BigInt
usually things will work if you use String
instead of string
, except that in some cases, the compiler will raise an error

As you can see, string
is assignable to String
, but String
is not assignable to string
.
Follow the advice in the error message and stick with string. All the type declarations that ship with TypeScript use it, as do the typings for almost all other libraries.