{"id":90,"date":"2024-02-27T20:15:22","date_gmt":"2024-02-27T20:15:22","guid":{"rendered":"https:\/\/codefulsoul.blog\/?p=90"},"modified":"2024-03-04T21:30:16","modified_gmt":"2024-03-04T21:30:16","slug":"insider-10x-developer","status":"publish","type":"post","link":"https:\/\/codefulsoul.blog\/index.php\/2024\/02\/27\/insider-10x-developer\/","title":{"rendered":"Insider 10x developer"},"content":{"rendered":"\n<p>I can&#8217;t remember <code>HTMLDivElement<\/code> and <code>HTMLImageElement<\/code><\/p>\n\n\n\n<p>Use u<code>seRef&lt;ElementRef&lt;'div'&gt;&gt;(null)<\/code><\/p>\n\n\n\n<p>Reminder: Complex types of inheritance are never worth it.<\/p>\n\n\n\n<p>Remember: satisfies and &#8220;as const&#8221; are incredible.<\/p>\n\n\n\n<p><code>as const satisfies [Sum, Mul]<\/code> are most times better than specifying the return type (Gives the caller back complete immutable types!)<\/p>\n\n\n\n<p>Normalized Types from returns have problems. <\/p>\n\n\n\n<p>Never use discriminated unions without a kind\/type property:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> \/\/ Obvious example\n function f(a: number) : ({x: number} | {y:number})\n {\n\n    if (a === 0) {\n        return {x: 3} as const;\n    }\n    return {y: 4} as const;\n  }\n\n\/\/ TS error\nconsole.log(f(0).x === undefined)\n\/\/ TS error\nconsole.log(f(0).y === undefined)\nconsole.log(f(3))\nconsole.log(f(3))\nconsole.log(f(3))\n\n\n\/\/ Not so obvious example\nfunction json&lt;T >(o: T) : T {\n    return o; \n}\n\n\nfunction f2(a: number)\n {\n\n    if (a === 0) {\n        return json({x: 9});\n    }\n    return json({y: 4});\n  }\n\nconst result: ReturnType&lt;typeof f2> = f2(3);\n\n\/\/ error\nconsole.log(f2(0).x === undefined)\n\/\/ error\nconsole.log(f2(0).y === undefined)\n<\/code><\/pre>\n\n\n\n<p>Sources<br>https:\/\/www.totaltypescript.com\/strongly-type-useref-with-elementref<br>https:\/\/twitter.com\/pcattori\/status\/1598359344827056131<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I can&#8217;t remember HTMLDivElement and HTMLImageElement Use useRef&lt;ElementRef&lt;&#8216;div&#8217;&gt;&gt;(null) Reminder: Complex types of inheritance are never worth it. Remember: satisfies and &#8220;as const&#8221; are incredible. as const satisfies [Sum, Mul] are most times better than specifying the return type (Gives the caller back complete immutable types!) Normalized Types from returns have problems. Never use discriminated unions [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-90","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/codefulsoul.blog\/index.php\/wp-json\/wp\/v2\/posts\/90","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codefulsoul.blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codefulsoul.blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codefulsoul.blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codefulsoul.blog\/index.php\/wp-json\/wp\/v2\/comments?post=90"}],"version-history":[{"count":4,"href":"https:\/\/codefulsoul.blog\/index.php\/wp-json\/wp\/v2\/posts\/90\/revisions"}],"predecessor-version":[{"id":95,"href":"https:\/\/codefulsoul.blog\/index.php\/wp-json\/wp\/v2\/posts\/90\/revisions\/95"}],"wp:attachment":[{"href":"https:\/\/codefulsoul.blog\/index.php\/wp-json\/wp\/v2\/media?parent=90"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codefulsoul.blog\/index.php\/wp-json\/wp\/v2\/categories?post=90"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codefulsoul.blog\/index.php\/wp-json\/wp\/v2\/tags?post=90"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}