5 Commandments for TypeScript programmers Milosz Piechocki on July 17, 2019 More and more projects and teams are adopting TypeScript. However, there is a massive difference between just using TypeScript and taking the most ... Read full post Submit Preview Dismiss Collapse Expand Alex Lohr Alex Lohr Alex Lohr Follow ...former musician, voice actor, martial artist, started coding 38 years ago and turned front-end developer 25+ years ago. Email alex.th.kloss.77@googlemail.com Location Germany Work Senior Frontend Developer at CrabNebula Joined Jun 13, 2017 • Jul 20 '19 Dropdown menu Copy link Hide I think it is ok to lie a bit in unit tests as long as the testing data is complete enough not to introduce strange side effects. For the sake of precision, use enums whenever possible in such cases. Otherwise, a very good article. Thank you. Collapse Expand Milosz Piechocki Milosz Piechocki Milosz Piechocki Follow Engineering Manager in Frontend at Sumo Logic; functional programming enthusiast; public speaker; loves ⛰️ hiking. Location Warsaw, Poland Education University of Warsaw, Poland Work Engineering Manager at SumoLogic Joined Nov 21, 2018 • Jul 22 '19 Dropdown menu Copy link Hide Hey, thanks for reading! Regarding unit tests - agreed, I do this too. However, there are some pitfalls, which I mention here. use enums whenever possible in such cases I'd say most of the time a union of string literal types is good enough. Also, enums have a runtime cost (const enums do not, though). Collapse Expand Alex Lohr Alex Lohr Alex Lohr Follow ...former musician, voice actor, martial artist, started coding 38 years ago and turned front-end developer 25+ years ago. Email alex.th.kloss.77@googlemail.com Location Germany Work Senior Frontend Developer at CrabNebula Joined Jun 13, 2017 • Jul 22 '19 Dropdown menu Copy link Hide a union of string literal types is good enough You'll thank me later when you have to change the actual values one day (without having to change the enum's identifier). Actually, I have to admit I didn't even know that there were other enums than const enums. We live and learn. Milosz Piechocki Milosz Piechocki Milosz Piechocki Follow Engineering Manager in Frontend at Sumo Logic; functional programming enthusiast; public speaker; loves ⛰️ hiking. Location Warsaw, Poland Education University of Warsaw, Poland Work Engineering Manager at SumoLogic Joined Nov 21, 2018 • Jul 23 '19 Dropdown menu Copy link Hide You'll thank me later when you have to change the actual values one day (without having to change the enum's identifier). Yes, good point :) Collapse Expand Vadim Belorussov Vadim Belorussov Vadim Belorussov Follow Joined Jul 25, 2019 • Jul 25 '19 Dropdown menu Copy link Hide Great post with simple and useful advice. Thank you! I would like to translate this article into Russian to publish it on specialized resource, but I need your permission first. Would you mind? Collapse Expand Milosz Piechocki Milosz Piechocki Milosz Piechocki Follow Engineering Manager in Frontend at Sumo Logic; functional programming enthusiast; public speaker; loves ⛰️ hiking. Location Warsaw, Poland Education University of Warsaw, Poland Work Engineering Manager at SumoLogic Joined Nov 21, 2018 • Jul 25 '19 Dropdown menu Copy link Hide Thank you! Sure, that would be great! Just please include the link back to the original article :) Also, if you let me know the URL of your translation, I can add some info about it here. Collapse Expand Vadim Belorussov Vadim Belorussov Vadim Belorussov Follow Joined Jul 25, 2019 • Jul 28 '19 Dropdown menu Copy link Hide I've translated your article into Russian and published it: 5 заповедей TypeScript-разработчика Milosz Piechocki Milosz Piechocki Milosz Piechocki Follow Engineering Manager in Frontend at Sumo Logic; functional programming enthusiast; public speaker; loves ⛰️ hiking. Location Warsaw, Poland Education University of Warsaw, Poland Work Engineering Manager at SumoLogic Joined Nov 21, 2018 • Jul 29 '19 Dropdown menu Copy link Hide Wow, that was fast! I added the link at the top of the article. Milosz Piechocki Milosz Piechocki Milosz Piechocki Follow Engineering Manager in Frontend at Sumo Logic; functional programming enthusiast; public speaker; loves ⛰️ hiking. Location Warsaw, Poland Education University of Warsaw, Poland Work Engineering Manager at SumoLogic Joined Nov 21, 2018 • Jul 29 '19 Dropdown menu Copy link Hide BTW, if you're interested in translating more TS articles, you can find some of mine here: codewithstyle.info/tags/typescript/ Collapse Expand Vadim Belorussov Vadim Belorussov Vadim Belorussov Follow Joined Jul 25, 2019 • Jul 25 '19 Dropdown menu Copy link Hide Sure, no problem. Thank you! Collapse Expand LuisPa LuisPa LuisPa Follow software gardener | everybody so judgemental. Location internet Joined Mar 25, 2017 • Jul 24 '19 Dropdown menu Copy link Hide Awesome post! Collapse Expand Milosz Piechocki Milosz Piechocki Milosz Piechocki Follow Engineering Manager in Frontend at Sumo Logic; functional programming enthusiast; public speaker; loves ⛰️ hiking. Location Warsaw, Poland Education University of Warsaw, Poland Work Engineering Manager at SumoLogic Joined Nov 21, 2018 • Jul 24 '19 Dropdown menu Copy link Hide Thank you! Code of Conduct • Report abuse
I think it is ok to lie a bit in unit tests as long as the testing data is complete enough not to introduce strange side effects.
For the sake of precision, use enums whenever possible in such cases.
Otherwise, a very good article. Thank you.
Hey, thanks for reading!
Regarding unit tests - agreed, I do this too. However, there are some pitfalls, which I mention here.
I'd say most of the time a union of string literal types is good enough. Also, enums have a runtime cost (
constenums do not, though).You'll thank me later when you have to change the actual values one day (without having to change the enum's identifier).
Actually, I have to admit I didn't even know that there were other enums than const enums. We live and learn.
Yes, good point :)
Great post with simple and useful advice. Thank you!
I would like to translate this article into Russian to publish it on specialized resource, but I need your permission first. Would you mind?
Thank you!
Sure, that would be great! Just please include the link back to the original article :)
Also, if you let me know the URL of your translation, I can add some info about it here.
I've translated your article into Russian and published it: 5 заповедей TypeScript-разработчика
Wow, that was fast! I added the link at the top of the article.
BTW, if you're interested in translating more TS articles, you can find some of mine here: codewithstyle.info/tags/typescript/
Sure, no problem. Thank you!
Awesome post!
Thank you!