{"componentChunkName":"component---src-templates-handbook-tsx","path":"/docs/handbook/utility-types.html","result":{"data":{"markdownRemark":{"id":"ec503eb7-425c-5064-a12a-dff2fbc70672","excerpt":"Introduction TypeScript provides several utility types to facilitate common type transformations. These utilities are available globally. Table of contents…","html":"<h1 id=\"introduction\"><a href=\"#introduction\" aria-label=\"introduction permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Introduction</h1>\n<p>TypeScript provides several utility types to facilitate common type transformations. These utilities are available globally.</p>\n<h2 id=\"table-of-contents\"><a href=\"#table-of-contents\" aria-label=\"table of contents permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Table of contents</h2>\n<ul>\n<li><a href=\"#partialt\"><code>Partial&#x3C;T></code></a></li>\n<li><a href=\"#readonlyt\"><code>Readonly&#x3C;T></code></a></li>\n<li><a href=\"#recordkt\"><code>Record&#x3C;K,T></code></a></li>\n<li><a href=\"#picktk\"><code>Pick&#x3C;T,K></code></a></li>\n<li><a href=\"#omittk\"><code>Omit&#x3C;T,K></code></a></li>\n<li><a href=\"#excludetu\"><code>Exclude&#x3C;T,U></code></a></li>\n<li><a href=\"#extracttu\"><code>Extract&#x3C;T,U></code></a></li>\n<li><a href=\"#nonnullablet\"><code>NonNullable&#x3C;T></code></a></li>\n<li><a href=\"#returntypet\"><code>ReturnType&#x3C;T></code></a></li>\n<li><a href=\"#instancetypet\"><code>InstanceType&#x3C;T></code></a></li>\n<li><a href=\"#requiredt\"><code>Required&#x3C;T></code></a></li>\n<li><a href=\"#thistypet\"><code>ThisType&#x3C;T></code></a></li>\n</ul>\n<h1 id=\"partialt\"><a href=\"#partialt\" aria-label=\"partialt permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code>Partial&#x3C;T></code></h1>\n<p>Constructs a type with all properties of <code>T</code> set to optional. This utility will return a type that represents all subsets of a given type.</p>\n<h5 id=\"example\"><a href=\"#example\" aria-label=\"example permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">interface</span><span style=\"color: #000000\"> Todo {</span>\n<span style=\"color: #000000\">    title: string;</span>\n<span style=\"color: #000000\">    description: string;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> updateTodo(todo: Todo, fieldsToUpdate: Partial&lt;Todo&gt;) {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> { ...todo, ...fieldsToUpdate };</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> todo1 = {</span>\n<span style=\"color: #000000\">    title: </span><span style=\"color: #A31515\">'organize desk'</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">    description: </span><span style=\"color: #A31515\">'clear clutter'</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">};</span>\n\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> todo2 = updateTodo(todo1, {</span>\n<span style=\"color: #000000\">    description: </span><span style=\"color: #A31515\">'throw out trash'</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">});</span></code></div></pre>\n<h1 id=\"readonlyt\"><a href=\"#readonlyt\" aria-label=\"readonlyt permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code>Readonly&#x3C;T></code></h1>\n<p>Constructs a type with all properties of <code>T</code> set to <code>readonly</code>, meaning the properties of the constructed type cannot be reassigned.</p>\n<h5 id=\"example-1\"><a href=\"#example-1\" aria-label=\"example 1 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">interface</span><span style=\"color: #000000\"> Todo {</span>\n<span style=\"color: #000000\">    title: string;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> todo: Readonly&lt;Todo&gt; = {</span>\n<span style=\"color: #000000\">    title: </span><span style=\"color: #A31515\">'Delete inactive users'</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">};</span>\n\n<span style=\"color: #000000\">todo.title = </span><span style=\"color: #A31515\">'Hello'</span><span style=\"color: #000000\">; </span><span style=\"color: #008000\">// Error: cannot reassign a readonly property</span></code></div></pre>\n<p>This utility is useful for representing assignment expressions that will fail at runtime (i.e. when attempting to reassign properties of a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze\">frozen object</a>).</p>\n<h5 id=\"objectfreeze\"><a href=\"#objectfreeze\" aria-label=\"objectfreeze permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code>Object.freeze</code></h5>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> freeze&lt;T&gt;(obj: T): Readonly&lt;T&gt;;</span></code></div></pre>\n<h1 id=\"recordkt\"><a href=\"#recordkt\" aria-label=\"recordkt permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code>Record&#x3C;K,T></code></h1>\n<p>Constructs a type with a set of properties <code>K</code> of type <code>T</code>. This utility can be used to map the properties of a type to another type.</p>\n<h5 id=\"example-2\"><a href=\"#example-2\" aria-label=\"example 2 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">interface</span><span style=\"color: #000000\"> PageInfo {</span>\n<span style=\"color: #000000\">    title: string;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> Page = </span><span style=\"color: #A31515\">'home'</span><span style=\"color: #000000\"> | </span><span style=\"color: #A31515\">'about'</span><span style=\"color: #000000\"> | </span><span style=\"color: #A31515\">'contact'</span><span style=\"color: #000000\">;</span>\n\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> x: Record&lt;Page, PageInfo&gt; = {</span>\n<span style=\"color: #000000\">    about: { title: </span><span style=\"color: #A31515\">'about'</span><span style=\"color: #000000\"> },</span>\n<span style=\"color: #000000\">    contact: { title: </span><span style=\"color: #A31515\">'contact'</span><span style=\"color: #000000\"> },</span>\n<span style=\"color: #000000\">    home: { title: </span><span style=\"color: #A31515\">'home'</span><span style=\"color: #000000\"> },</span>\n<span style=\"color: #000000\">};</span></code></div></pre>\n<h1 id=\"picktk\"><a href=\"#picktk\" aria-label=\"picktk permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code>Pick&#x3C;T,K></code></h1>\n<p>Constructs a type by picking the set of properties <code>K</code> from <code>T</code>.</p>\n<h5 id=\"example-3\"><a href=\"#example-3\" aria-label=\"example 3 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">interface</span><span style=\"color: #000000\"> Todo {</span>\n<span style=\"color: #000000\">    title: string;</span>\n<span style=\"color: #000000\">    description: string;</span>\n<span style=\"color: #000000\">    completed: boolean;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> TodoPreview = Pick&lt;Todo, </span><span style=\"color: #A31515\">'title'</span><span style=\"color: #000000\"> | </span><span style=\"color: #A31515\">'completed'</span><span style=\"color: #000000\">&gt;;</span>\n\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> todo: TodoPreview = {</span>\n<span style=\"color: #000000\">    title: </span><span style=\"color: #A31515\">'Clean room'</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">    completed: </span><span style=\"color: #0000FF\">false</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">};</span></code></div></pre>\n<h1 id=\"omittk\"><a href=\"#omittk\" aria-label=\"omittk permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code>Omit&#x3C;T,K></code></h1>\n<p>Constructs a type by picking all properties from <code>T</code> and then removing <code>K</code>.</p>\n<h5 id=\"example-4\"><a href=\"#example-4\" aria-label=\"example 4 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">interface</span><span style=\"color: #000000\"> Todo {</span>\n<span style=\"color: #000000\">    title: string;</span>\n<span style=\"color: #000000\">    description: string;</span>\n<span style=\"color: #000000\">    completed: boolean;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> TodoPreview = Omit&lt;Todo, </span><span style=\"color: #A31515\">'description'</span><span style=\"color: #000000\">&gt;;</span>\n\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> todo: TodoPreview = {</span>\n<span style=\"color: #000000\">    title: </span><span style=\"color: #A31515\">'Clean room'</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">    completed: </span><span style=\"color: #0000FF\">false</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">};</span></code></div></pre>\n<h1 id=\"excludetu\"><a href=\"#excludetu\" aria-label=\"excludetu permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code>Exclude&#x3C;T,U></code></h1>\n<p>Constructs a type by excluding from <code>T</code> all properties that are assignable to <code>U</code>.</p>\n<h5 id=\"example-5\"><a href=\"#example-5\" aria-label=\"example 5 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T0 = Exclude&lt;</span><span style=\"color: #A31515\">\"a\"</span><span style=\"color: #000000\"> | </span><span style=\"color: #A31515\">\"b\"</span><span style=\"color: #000000\"> | </span><span style=\"color: #A31515\">\"c\"</span><span style=\"color: #000000\">, </span><span style=\"color: #A31515\">\"a\"</span><span style=\"color: #000000\">&gt;;  </span><span style=\"color: #008000\">// \"b\" | \"c\"</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T1 = Exclude&lt;</span><span style=\"color: #A31515\">\"a\"</span><span style=\"color: #000000\"> | </span><span style=\"color: #A31515\">\"b\"</span><span style=\"color: #000000\"> | </span><span style=\"color: #A31515\">\"c\"</span><span style=\"color: #000000\">, </span><span style=\"color: #A31515\">\"a\"</span><span style=\"color: #000000\"> | </span><span style=\"color: #A31515\">\"b\"</span><span style=\"color: #000000\">&gt;;  </span><span style=\"color: #008000\">// \"c\"</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T2 = Exclude&lt;string | number | (() </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> void), Function&gt;;  </span><span style=\"color: #008000\">// string | number</span></code></div></pre>\n<h1 id=\"extracttu\"><a href=\"#extracttu\" aria-label=\"extracttu permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code>Extract&#x3C;T,U></code></h1>\n<p>Constructs a type by extracting from <code>T</code> all properties that are assignable to <code>U</code>.</p>\n<h5 id=\"example-6\"><a href=\"#example-6\" aria-label=\"example 6 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T0 = Extract&lt;</span><span style=\"color: #A31515\">\"a\"</span><span style=\"color: #000000\"> | </span><span style=\"color: #A31515\">\"b\"</span><span style=\"color: #000000\"> | </span><span style=\"color: #A31515\">\"c\"</span><span style=\"color: #000000\">, </span><span style=\"color: #A31515\">\"a\"</span><span style=\"color: #000000\"> | </span><span style=\"color: #A31515\">\"f\"</span><span style=\"color: #000000\">&gt;;  </span><span style=\"color: #008000\">// \"a\"</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T1 = Extract&lt;string | number | (() </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> void), Function&gt;;  </span><span style=\"color: #008000\">// () =&gt; void</span></code></div></pre>\n<h1 id=\"nonnullablet\"><a href=\"#nonnullablet\" aria-label=\"nonnullablet permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code>NonNullable&#x3C;T></code></h1>\n<p>Constructs a type by excluding <code>null</code> and <code>undefined</code> from <code>T</code>.</p>\n<h5 id=\"example-7\"><a href=\"#example-7\" aria-label=\"example 7 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T0 = NonNullable&lt;string | number | undefined&gt;;  </span><span style=\"color: #008000\">// string | number</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T1 = NonNullable&lt;string[] | null | undefined&gt;;  </span><span style=\"color: #008000\">// string[]</span></code></div></pre>\n<h1 id=\"returntypet\"><a href=\"#returntypet\" aria-label=\"returntypet permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code>ReturnType&#x3C;T></code></h1>\n<p>Constructs a type consisting of the return type of function <code>T</code>.</p>\n<h5 id=\"example-8\"><a href=\"#example-8\" aria-label=\"example 8 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T0 = ReturnType&lt;() </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> string&gt;;  </span><span style=\"color: #008000\">// string</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T1 = ReturnType&lt;(s: string) </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> void&gt;;  </span><span style=\"color: #008000\">// void</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T2 = ReturnType&lt;(&lt;T&gt;() </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> T)&gt;;  </span><span style=\"color: #008000\">// {}</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T3 = ReturnType&lt;(&lt;T </span><span style=\"color: #0000FF\">extends</span><span style=\"color: #000000\"> U, U </span><span style=\"color: #0000FF\">extends</span><span style=\"color: #000000\"> number[]&gt;() </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> T)&gt;;  </span><span style=\"color: #008000\">// number[]</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T4 = ReturnType&lt;</span><span style=\"color: #0000FF\">typeof</span><span style=\"color: #000000\"> f1&gt;;  </span><span style=\"color: #008000\">// { a: number, b: string }</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T5 = ReturnType&lt;any&gt;;  </span><span style=\"color: #008000\">// any</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T6 = ReturnType&lt;never&gt;;  </span><span style=\"color: #008000\">// any</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T7 = ReturnType&lt;string&gt;;  </span><span style=\"color: #008000\">// Error</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T8 = ReturnType&lt;Function&gt;;  </span><span style=\"color: #008000\">// Error</span></code></div></pre>\n<h1 id=\"instancetypet\"><a href=\"#instancetypet\" aria-label=\"instancetypet permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code>InstanceType&#x3C;T></code></h1>\n<p>Constructs a type consisting of the instance type of a constructor function type <code>T</code>.</p>\n<h5 id=\"example-9\"><a href=\"#example-9\" aria-label=\"example 9 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> C {</span>\n<span style=\"color: #000000\">    x = </span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">    y = </span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T0 = InstanceType&lt;</span><span style=\"color: #0000FF\">typeof</span><span style=\"color: #000000\"> C&gt;;  </span><span style=\"color: #008000\">// C</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T1 = InstanceType&lt;any&gt;;  </span><span style=\"color: #008000\">// any</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T2 = InstanceType&lt;never&gt;;  </span><span style=\"color: #008000\">// any</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T3 = InstanceType&lt;string&gt;;  </span><span style=\"color: #008000\">// Error</span>\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> T4 = InstanceType&lt;Function&gt;;  </span><span style=\"color: #008000\">// Error</span></code></div></pre>\n<h1 id=\"requiredt\"><a href=\"#requiredt\" aria-label=\"requiredt permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code>Required&#x3C;T></code></h1>\n<p>Constructs a type consisting of all properties of <code>T</code> set to required.</p>\n<h5 id=\"example-10\"><a href=\"#example-10\" aria-label=\"example 10 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">interface</span><span style=\"color: #000000\"> Props {</span>\n<span style=\"color: #000000\">    a?: number;</span>\n<span style=\"color: #000000\">    b?: string;</span>\n<span style=\"color: #000000\">};</span>\n\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> obj: Props = { a: </span><span style=\"color: #09835A\">5</span><span style=\"color: #000000\"> }; </span><span style=\"color: #008000\">// OK</span>\n\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> obj2: Required&lt;Props&gt; = { a: </span><span style=\"color: #09835A\">5</span><span style=\"color: #000000\"> }; </span><span style=\"color: #008000\">// Error: property 'b' missing</span></code></div></pre>\n<h1 id=\"thistypet\"><a href=\"#thistypet\" aria-label=\"thistypet permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code>ThisType&#x3C;T></code></h1>\n<p>This utility does not return a transformed type. Instead, it serves as a marker for a contextual <code>this</code> type. Note that the <code>--noImplicitThis</code> flag must be enabled to use this utility.</p>\n<h5 id=\"example-11\"><a href=\"#example-11\" aria-label=\"example 11 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Example</h5>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// Compile with --noImplicitThis</span>\n\n<span style=\"color: #0000FF\">type</span><span style=\"color: #000000\"> ObjectDescriptor&lt;D, M&gt; = {</span>\n<span style=\"color: #000000\">    data?: D;</span>\n<span style=\"color: #000000\">    methods?: M & ThisType&lt;D & M&gt;;  </span><span style=\"color: #008000\">// Type of 'this' in methods is D & M</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> makeObject&lt;D, M&gt;(desc: ObjectDescriptor&lt;D, M&gt;): D & M {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> data: object = desc.data || {};</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> methods: object = desc.methods || {};</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> { ...data, ...methods } </span><span style=\"color: #0000FF\">as</span><span style=\"color: #000000\"> D & M;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> obj = makeObject({</span>\n<span style=\"color: #000000\">    data: { x: </span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">, y: </span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\"> },</span>\n<span style=\"color: #000000\">    methods: {</span>\n<span style=\"color: #000000\">        moveBy(dx: number, dy: number) {</span>\n<span style=\"color: #000000\">            </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.x += dx;  </span><span style=\"color: #008000\">// Strongly typed this</span>\n<span style=\"color: #000000\">            </span><span style=\"color: #0000FF\">this</span><span style=\"color: #000000\">.y += dy;  </span><span style=\"color: #008000\">// Strongly typed this</span>\n<span style=\"color: #000000\">        }</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">});</span>\n\n<span style=\"color: #000000\">obj.x = </span><span style=\"color: #09835A\">10</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">obj.y = </span><span style=\"color: #09835A\">20</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">obj.moveBy(</span><span style=\"color: #09835A\">5</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">5</span><span style=\"color: #000000\">);</span></code></div></pre>\n<p>In the example above, the <code>methods</code> object in the argument to <code>makeObject</code> has a contextual type that includes <code>ThisType&#x3C;D &#x26; M></code> and therefore the type of <code>this</code> in methods within the <code>methods</code> object is <code>{ x: number, y: number } &#x26; { moveBy(dx: number, dy: number): number }</code>. Notice how the type of the <code>methods</code> property simultaneously is an inference target and a source for the <code>this</code> type in methods.</p>\n<p>The <code>ThisType&#x3C;T></code> marker interface is simply an empty interface declared in <code>lib.d.ts</code>. Beyond being recognized in the contextual type of an object literal, the interface acts like any empty interface.</p>","headings":[{"value":"Introduction","depth":1},{"value":"Table of contents","depth":2},{"value":"Partial<T>","depth":1},{"value":"Example","depth":5},{"value":"Readonly<T>","depth":1},{"value":"Example","depth":5},{"value":"Object.freeze","depth":5},{"value":"Record<K,T>","depth":1},{"value":"Example","depth":5},{"value":"Pick<T,K>","depth":1},{"value":"Example","depth":5},{"value":"Omit<T,K>","depth":1},{"value":"Example","depth":5},{"value":"Exclude<T,U>","depth":1},{"value":"Example","depth":5},{"value":"Extract<T,U>","depth":1},{"value":"Example","depth":5},{"value":"NonNullable<T>","depth":1},{"value":"Example","depth":5},{"value":"ReturnType<T>","depth":1},{"value":"Example","depth":5},{"value":"InstanceType<T>","depth":1},{"value":"Example","depth":5},{"value":"Required<T>","depth":1},{"value":"Example","depth":5},{"value":"ThisType<T>","depth":1},{"value":"Example","depth":5}],"frontmatter":{"permalink":"/docs/handbook/utility-types.html","title":"Utility Types"}}},"pageContext":{"slug":"/docs/handbook/utility-types.html","isOldHandbook":true}}}