{"id":12170,"date":"2026-01-05T21:40:01","date_gmt":"2026-01-05T21:40:01","guid":{"rendered":"https:\/\/putridparrot.com\/blog\/?p=12170"},"modified":"2026-01-05T21:40:01","modified_gmt":"2026-01-05T21:40:01","slug":"returntype-and-parameters-in-typescript","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/returntype-and-parameters-in-typescript\/","title":{"rendered":"ReturnType and Parameters in Typescript"},"content":{"rendered":"<p>Typescript has a couple of types which are useful for describing types when none are strictly specified. <\/p>\n<p>Let&#8217;s assume we have this simple function, which takes a string parameter and returns <\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction getData(key: string) {\r\n   return { key, firstName: &quot;Scooby&quot;, lastName: &quot;Doo&quot; }\r\n}\r\n<\/pre>\n<p>Using <em>ReturnType<\/em> creates a type that matches the getData return. i.e. { key: string, firstName: string, lastName: string } whereas the Parameters will be a tuple [key: string]<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\ntype T = ReturnType&lt;typeof getData&gt;;\r\ntype T = Parameters&lt;typeof getData&gt;;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Typescript has a couple of types which are useful for describing types when none are strictly specified. Let&#8217;s assume we have this simple function, which takes a string parameter and returns function getData(key: string) { return { key, firstName: &quot;Scooby&quot;, lastName: &quot;Doo&quot; } } Using ReturnType creates a type that matches the getData return. i.e. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[46],"tags":[],"class_list":["post-12170","post","type-post","status-publish","format-standard","hentry","category-typescript"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/12170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=12170"}],"version-history":[{"count":2,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/12170\/revisions"}],"predecessor-version":[{"id":12172,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/12170\/revisions\/12172"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=12170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=12170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=12170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}