{"id":2932,"date":"2024-07-04T11:14:38","date_gmt":"2024-07-04T17:14:38","guid":{"rendered":"https:\/\/frontendmasters.com\/blog\/?p=2932"},"modified":"2024-07-04T11:15:29","modified_gmt":"2024-07-04T17:15:29","slug":"primitive-obsession","status":"publish","type":"post","link":"https:\/\/frontendmasters.com\/blog\/primitive-obsession\/","title":{"rendered":"Primitive Obsession"},"content":{"rendered":"\n<p>I found this essay <a href=\"https:\/\/acairns.co.uk\/posts\/primitive-obsession\">Primitive Obsession<\/a> by Andrew Cairns interesting. The big example in it is this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">$user = <span class=\"hljs-keyword\">new<\/span> User(<span class=\"hljs-string\">'abc123'<\/span>, <span class=\"hljs-string\">'email@address.com'<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Here the <code>User<\/code> function takes two <code>string<\/code> params, <code>string<\/code> being a primitive type, and here, quite easy to screw up by passing them in the wrong order and\/or not pre-validating the values. If you agree, there are a variety of ways to tackle this problem which generally boil down to passing in a typed object. TypeScript and Zod fans will be like: yeah duh.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I found this essay Primitive Obsession by Andrew Cairns interesting. The big example in it is this: Here the User function takes two string params, string being a primitive type, and here, quite easy to screw up by passing them in the wrong order and\/or not pre-validating the values. If you agree, there are a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2933,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[29],"tags":[3],"class_list":["post-2932","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-the-beat","tag-javascript"],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/07\/cHJpdmF0ZS9sci9pbWFnZXMvd2Vic2l0ZS8yMDIyLTA0L21hc3Rlci1wbnAtbXJnLTAzNjAwLTAzNjE2YS5qcGc.webp?fit=1024%2C711&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/2932","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/comments?post=2932"}],"version-history":[{"count":2,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/2932\/revisions"}],"predecessor-version":[{"id":2935,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/2932\/revisions\/2935"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media\/2933"}],"wp:attachment":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media?parent=2932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/categories?post=2932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/tags?post=2932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}