DEV Community

Calin Baenen
Calin Baenen

Posted on

Feature reveal for my JS library (HotTea); Typed objects.

I'm adding typed objects to JS in HotTea (along with the promised "real classes").

This is how they look so far:

je = TypedObject({
  "name": String,
  "age": Number
});

je.name // null
je.age // null


je.name = null; // That's fine.
je.name = new Object(); // TypeError: Type Object does not match required type String.
je.name = "John"; // TypeError: Type String does not match required type String.
// Gonna fix the message to account for primitive type names.


je.name = new String("John Egbert");
je.age = new Number(13);

je.name; // John Egbert
Enter fullscreen mode Exit fullscreen mode

There also is a way to use primitive types as their Object equivalents (using the strict parameter):

ds = TypedObject({
  "creator": Object,
  "name": String
}, false);

ds.creator = "test"; // Throws an error (because I still need to implement the proper behavior).
ds.creator = new String("Andrew Hussie");
ds.name = "Dave Strider";
Enter fullscreen mode Exit fullscreen mode

I also do wanna be able to add a way to add new properties later on, but that's gonna be hard due to the current architecture. But, I hope you all are excited for HotTea!

Thanks for reading!
Cheers!

Top comments (11)

Collapse
 
potentialstyx profile image
PotentialStyx

Looking forward for the full release of the library :D

Collapse
 
baenencalin profile image
Calin Baenen

Thanks. Can't wait to release the first version (a0.01) containing TypedObjects and a few comparison utils.

Collapse
 
potentialstyx profile image
PotentialStyx

Quick question: will there be a github repo for it (or is there already one)

Thread Thread
 
baenencalin profile image
Calin Baenen

There's an OLD version on GH, if you'd like to see. But yes, (new) HotTea will get its own repo.

Thread Thread
 
potentialstyx profile image
PotentialStyx

Ok. Have fun working on it!

Thread Thread
 
baenencalin profile image
Calin Baenen

Want to see the old version?

Thread Thread
 
potentialstyx profile image
PotentialStyx

Sure

Thread Thread
 
potentialstyx profile image
PotentialStyx
Thread Thread
 
baenencalin profile image
Calin Baenen

Yes.
Sorry it took me a minute to find, and a minute to respond. I was on mobile, and getting on PC.

Thread Thread
 
baenencalin profile image
Calin Baenen

What do you think of the old version?

Thread Thread
 
potentialstyx profile image
PotentialStyx

That's ok :D. I gotta go now, good luck with that library