Primitive<T>:Equal<T, PrimitiveMain<T>> extends true ? T : PrimitiveMain<T>
Primitive type of JSON.
Primitive<T> is a TMP (Type Meta Programming) type which converts
its argument as a primitive type within framework JSON.
If the target argument is a built-in class which returns its origin primitive type
through the valueOf() method like the String or Number, its return type would
be the string or number. Otherwise, the built-in class does not have the
valueOf() method, the return type would be an empty object ({}).
Otherwise, the target argument is a type of custom class, all of its custom method
would be erased and its prototype would be changed to the primitive object.
Therefore, return type of the TMP type finally be the primitive object.
In addition, if the target argument is a type of custom class and it has a special
method toJSON(), return type of this Primitive would be not Primitive<Instance>
but Primitive<ReturnType<Instance.toJSON>>.
Primitive type of JSON.
Primitive<T>
is a TMP (Type Meta Programming) type which converts its argument as a primitive type within framework JSON.If the target argument is a built-in class which returns its origin primitive type through the
valueOf()
method like theString
orNumber
, its return type would be thestring
ornumber
. Otherwise, the built-in class does not have thevalueOf()
method, the return type would be an empty object ({}
).Otherwise, the target argument is a type of custom class, all of its custom method would be erased and its prototype would be changed to the primitive
object
. Therefore, return type of the TMP type finally be the primitive object.In addition, if the target argument is a type of custom class and it has a special method
toJSON()
, return type of thisPrimitive
would be notPrimitive<Instance>
butPrimitive<ReturnType<Instance.toJSON>>
.Boolean
boolean
Number
number
String
string
Class
object
Class
withtoJSON()
Primitive<ReturnType<Class.toJSON>>