You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Avoid TypeScript object wrapper types. Use the primitive types instead: string instead of String, number instead of Number, boolean instead of Boolean, symbol instead of Symbol, and bigint instead of BigInt.
Understand how object wrapper types are used to provide methods on primitive values. Avoid instantiating them or using them directly, with the exception of Symbol and BigInt.
Code Samples
// Don't do this!constoriginalCharAt=String.prototype.charAt;String.prototype.charAt=function(pos){console.log(this,typeofthis,pos);returnoriginalCharAt.call(this,pos);};console.log('primitive'.charAt(3));
functionisGreeting(phrase: String){return['hello','good day'].includes(phrase);// ~~~~~~// Argument of type 'String' is not assignable to parameter of type 'string'.// 'string' is a primitive, but 'String' is a wrapper object.// Prefer using 'string' when possible.}