DEV Community

loading...

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

baenencalin profile image Calin Baenen ・1 min read

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!

Discussion (11)

pic
Editor guide
Collapse
codemonkey51 profile image
Codemonkey51

Looking forward for the full release of the library :D

Collapse
baenencalin profile image
Calin Baenen Author

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

Collapse
codemonkey51 profile image
Codemonkey51

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

Thread Thread
baenencalin profile image
Calin Baenen Author

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

Thread Thread
codemonkey51 profile image
Codemonkey51

Ok. Have fun working on it!

Thread Thread
baenencalin profile image
Calin Baenen Author

Want to see the old version?

Thread Thread
codemonkey51 profile image
Thread Thread
codemonkey51 profile image
Thread Thread
baenencalin profile image
Calin Baenen Author

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 Author

What do you think of the old version?

Thread Thread
codemonkey51 profile image
Codemonkey51

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