{"componentChunkName":"component---src-templates-handbook-tsx","path":"/docs/handbook/declaration-files/by-example.html","result":{"data":{"markdownRemark":{"id":"94ed3900-5f2e-5cbc-9f3c-0f8c50bbeaed","excerpt":"Introduction The purpose of this guide is to teach you how to write a high-quality definition file.\nThis guide is structured by showing documentation for some…","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>The purpose of this guide is to teach you how to write a high-quality definition file.\nThis guide is structured by showing documentation for some API, along with sample usage of that API,\nand explaining how to write the corresponding declaration.</p>\n<p>These examples are ordered in approximately increasing order of complexity.</p>\n<ul>\n<li><a href=\"#global-variables\">Global Variables</a></li>\n<li><a href=\"#global-functions\">Global Functions</a></li>\n<li><a href=\"#objects-with-properties\">Objects with Properties</a></li>\n<li><a href=\"#overloaded-functions\">Overloaded Function</a></li>\n<li><a href=\"#reusable-types-interfaces\">Reusable Types (Interfaces)</a></li>\n<li><a href=\"#reusable-types-type-aliases\">Reusable Types (Type Aliases)</a></li>\n<li><a href=\"#organizing-types\">Organizing Types</a></li>\n<li><a href=\"#classes\">Classes</a></li>\n</ul>\n<h1 id=\"the-examples\"><a href=\"#the-examples\" aria-label=\"the examples 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>The Examples</h1>\n<h2 id=\"global-variables\"><a href=\"#global-variables\" aria-label=\"global variables 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>Global Variables</h2>\n<p><em>Documentation</em></p>\n<blockquote>\n<p>The global variable <code>foo</code> contains the number of widgets present.</p>\n</blockquote>\n<p><em>Code</em></p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #000000\">console.log(</span><span style=\"color: #A31515\">\"Half the number of widgets is \"</span><span style=\"color: #000000\"> + (foo / </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">));</span></code></div></pre>\n<p><em>Declaration</em></p>\n<p>Use <code>declare var</code> to declare variables.\nIf the variable is read-only, you can use <code>declare const</code>.\nYou can also use <code>declare let</code> if the variable is block-scoped.</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">/** The number of widgets present */</span>\n<span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> foo: number;</span></code></div></pre>\n<h2 id=\"global-functions\"><a href=\"#global-functions\" aria-label=\"global functions 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>Global Functions</h2>\n<p><em>Documentation</em></p>\n<blockquote>\n<p>You can call the function <code>greet</code> with a string to show a greeting to the user.</p>\n</blockquote>\n<p><em>Code</em></p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #000000\">greet(</span><span style=\"color: #A31515\">\"hello, world\"</span><span style=\"color: #000000\">);</span></code></div></pre>\n<p><em>Declaration</em></p>\n<p>Use <code>declare function</code> to declare functions.</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> greet(greeting: string): void;</span></code></div></pre>\n<h2 id=\"objects-with-properties\"><a href=\"#objects-with-properties\" aria-label=\"objects with properties 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>Objects with Properties</h2>\n<p><em>Documentation</em></p>\n<blockquote>\n<p>The global variable <code>myLib</code> has a function <code>makeGreeting</code> for creating greetings,\nand a property <code>numberOfGreetings</code> indicating the number of greetings made so far.</p>\n</blockquote>\n<p><em>Code</em></p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> result = myLib.makeGreeting(</span><span style=\"color: #A31515\">\"hello, world\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">console.log(</span><span style=\"color: #A31515\">\"The computed greeting is:\"</span><span style=\"color: #000000\"> + result);</span>\n\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> count = myLib.numberOfGreetings;</span></code></div></pre>\n<p><em>Declaration</em></p>\n<p>Use <code>declare namespace</code> to describe types or values accessed by dotted notation.</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">namespace</span><span style=\"color: #000000\"> myLib {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> makeGreeting(s: string): string;</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> numberOfGreetings: number;</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h2 id=\"overloaded-functions\"><a href=\"#overloaded-functions\" aria-label=\"overloaded functions 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>Overloaded Functions</h2>\n<p><em>Documentation</em></p>\n<p>The <code>getWidget</code> function accepts a number and returns a Widget, or accepts a string and returns a Widget array.</p>\n<p><em>Code</em></p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> x: Widget = getWidget(</span><span style=\"color: #09835A\">43</span><span style=\"color: #000000\">);</span>\n\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> arr: Widget[] = getWidget(</span><span style=\"color: #A31515\">\"all of them\"</span><span style=\"color: #000000\">);</span></code></div></pre>\n<p><em>Declaration</em></p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> getWidget(n: number): Widget;</span>\n<span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> getWidget(s: string): Widget[];</span></code></div></pre>\n<h2 id=\"reusable-types-interfaces\"><a href=\"#reusable-types-interfaces\" aria-label=\"reusable types interfaces 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>Reusable Types (Interfaces)</h2>\n<p><em>Documentation</em></p>\n<blockquote>\n<p>When specifying a greeting, you must pass a <code>GreetingSettings</code> object.\nThis object has the following properties:</p>\n<p>1 - greeting: Mandatory string</p>\n<p>2 - duration: Optional length of time (in milliseconds)</p>\n<p>3 - color: Optional string, e.g. ‘#ff00ff’</p>\n</blockquote>\n<p><em>Code</em></p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #000000\">greet({</span>\n<span style=\"color: #000000\">  greeting: </span><span style=\"color: #A31515\">\"hello world\"</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">  duration: </span><span style=\"color: #09835A\">4000</span>\n<span style=\"color: #000000\">});</span></code></div></pre>\n<p><em>Declaration</em></p>\n<p>Use an <code>interface</code> to define a type with properties.</p>\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\"> GreetingSettings {</span>\n<span style=\"color: #000000\">  greeting: string;</span>\n<span style=\"color: #000000\">  duration?: number;</span>\n<span style=\"color: #000000\">  color?: string;</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> greet(setting: GreetingSettings): void;</span></code></div></pre>\n<h2 id=\"reusable-types-type-aliases\"><a href=\"#reusable-types-type-aliases\" aria-label=\"reusable types type aliases 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>Reusable Types (Type Aliases)</h2>\n<p><em>Documentation</em></p>\n<blockquote>\n<p>Anywhere a greeting is expected, you can provide a <code>string</code>, a function returning a <code>string</code>, or a <code>Greeter</code> instance.</p>\n</blockquote>\n<p><em>Code</em></p>\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\"> getGreeting() {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> </span><span style=\"color: #A31515\">\"howdy\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> MyGreeter </span><span style=\"color: #0000FF\">extends</span><span style=\"color: #000000\"> Greeter { }</span>\n\n<span style=\"color: #000000\">greet(</span><span style=\"color: #A31515\">\"hello\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">greet(getGreeting);</span>\n<span style=\"color: #000000\">greet(</span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> MyGreeter());</span></code></div></pre>\n<p><em>Declaration</em></p>\n<p>You can use a type alias to make a shorthand for a type:</p>\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\"> GreetingLike = string | (() </span><span style=\"color: #0000FF\">=&gt;</span><span style=\"color: #000000\"> string) | MyGreeter;</span>\n\n<span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> greet(g: GreetingLike): void;</span></code></div></pre>\n<h2 id=\"organizing-types\"><a href=\"#organizing-types\" aria-label=\"organizing types 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>Organizing Types</h2>\n<p><em>Documentation</em></p>\n<blockquote>\n<p>The <code>greeter</code> object can log to a file or display an alert.\nYou can provide LogOptions to <code>.log(...)</code> and alert options to <code>.alert(...)</code></p>\n</blockquote>\n<p><em>Code</em></p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> g = </span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> Greeter(</span><span style=\"color: #A31515\">\"Hello\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">g.log({ verbose: </span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\"> });</span>\n<span style=\"color: #000000\">g.alert({ modal: </span><span style=\"color: #0000FF\">false</span><span style=\"color: #000000\">, title: </span><span style=\"color: #A31515\">\"Current Greeting\"</span><span style=\"color: #000000\"> });</span></code></div></pre>\n<p><em>Declaration</em></p>\n<p>Use namespaces to organize types.</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">namespace</span><span style=\"color: #000000\"> GreetingLib {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">interface</span><span style=\"color: #000000\"> LogOptions {</span>\n<span style=\"color: #000000\">        verbose?: boolean;</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">interface</span><span style=\"color: #000000\"> AlertOptions {</span>\n<span style=\"color: #000000\">        modal: boolean;</span>\n<span style=\"color: #000000\">        title?: string;</span>\n<span style=\"color: #000000\">        color?: string;</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p>You can also create nested namespaces in one declaration:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">namespace</span><span style=\"color: #000000\"> GreetingLib.Options {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// Refer to via GreetingLib.Options.Log</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">interface</span><span style=\"color: #000000\"> Log {</span>\n<span style=\"color: #000000\">        verbose?: boolean;</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">interface</span><span style=\"color: #000000\"> Alert {</span>\n<span style=\"color: #000000\">        modal: boolean;</span>\n<span style=\"color: #000000\">        title?: string;</span>\n<span style=\"color: #000000\">        color?: string;</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h2 id=\"classes\"><a href=\"#classes\" aria-label=\"classes 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>Classes</h2>\n<p><em>Documentation</em></p>\n<blockquote>\n<p>You can create a greeter by instantiating the <code>Greeter</code> object, or create a customized greeter by extending from it.</p>\n</blockquote>\n<p><em>Code</em></p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> myGreeter = </span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> Greeter(</span><span style=\"color: #A31515\">\"hello, world\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">myGreeter.greeting = </span><span style=\"color: #A31515\">\"howdy\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">myGreeter.showGreeting();</span>\n\n<span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> SpecialGreeter </span><span style=\"color: #0000FF\">extends</span><span style=\"color: #000000\"> Greeter {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">constructor</span><span style=\"color: #000000\">() {</span>\n<span style=\"color: #000000\">        </span><span style=\"color: #0000FF\">super</span><span style=\"color: #000000\">(</span><span style=\"color: #A31515\">\"Very special greetings\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">    }</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<p><em>Declaration</em></p>\n<p>Use <code>declare class</code> to describe a class or class-like object.\nClasses can have properties and methods as well as a constructor.</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">class</span><span style=\"color: #000000\"> Greeter {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #0000FF\">constructor</span><span style=\"color: #000000\">(greeting: string);</span>\n\n<span style=\"color: #000000\">    greeting: string;</span>\n<span style=\"color: #000000\">    showGreeting(): void;</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<!-- Template\n\n##\n\n*Documentation*\n>\n\n*Code*\n\n```ts\n\n```\n\n*Declaration*\n\n```ts\n\n```\n\n-->","headings":[{"value":"Introduction","depth":1},{"value":"The Examples","depth":1},{"value":"Global Variables","depth":2},{"value":"Global Functions","depth":2},{"value":"Objects with Properties","depth":2},{"value":"Overloaded Functions","depth":2},{"value":"Reusable Types (Interfaces)","depth":2},{"value":"Reusable Types (Type Aliases)","depth":2},{"value":"Organizing Types","depth":2},{"value":"Classes","depth":2}],"frontmatter":{"permalink":"/docs/handbook/declaration-files/by-example.html","title":"By Example"}}},"pageContext":{"slug":"/docs/handbook/declaration-files/by-example.html","isOldHandbook":true}}}