TypexJS naming scheme applies to all primitive immutable types:
It extends to specific Object types:
The suffix specifying the type is an underscore character followed by a single letter:
Type | Suffix |
---|---|
Null | _N |
Undefined | _U |
Boolean | _b |
Number | _n |
String | _s |
Array | _a |
Object | _o |
Symbol | _y |
Class | _c |
RegExp | _r |
To convey even more meaningful information, function identifiers follow a slightly different scheme:
void
function
, we use the v letter for its suffix
a possible alternative is to use the undefined value: U
.Function return is | Suffix |
---|---|
Null | __N |
Undefined | __U |
Boolean | __b |
Number | __n |
String | __s |
Array | __a |
Object | __o |
Symbol | __y |
Class | __c |
RegExp | __r |
Function | __f |
Void | __v |
const awesome__s = () => 'An awesome String'
const clone__s = awesome__s
In case of a function returning different types of value, we just omit the type character.
const silly__ = string_b => string_b ? 'A weird String' : 1234
We could do the same for a variable accepting different kinds of type, but is it really a good practice?
let hybrid_ = 'A String'
hybrid_ = 1234 //: What a mess!