{"route":"/en-US-v0.13.1/reference/foundations/type/","title":"Type","description":"Documentation for the Type type.","part":null,"outline":[{"id":"summary","name":"Summary","children":[]},{"id":"example","name":"Example","children":[]},{"id":"compatibility","name":"Compatibility","children":[]},{"id":"constructor","name":"Constructor","children":[{"id":"constructor-value","name":"value","children":[]}]}],"body":{"kind":"type","content":{"name":"type","title":"Type","keywords":[],"oneliner":"Describes a kind of value.","details":"<p>Describes a kind of value.</p>\n<p>To style your document, you need to work with values of different kinds:\nLengths specifying the size of your elements, colors for your text and\nshapes, and more. Typst categorizes these into clearly defined <em>types</em> and\ntells you where it expects which type of value.</p>\n<p>Apart from basic types for numeric values and <a href=\"/en-US-v0.13.1/reference/foundations/int/\">typical</a>\n<a href=\"/en-US-v0.13.1/reference/foundations/float/\">types</a> <a href=\"/en-US-v0.13.1/reference/foundations/str/\">known</a> <a href=\"/en-US-v0.13.1/reference/foundations/array/\">from</a> <a href=\"/en-US-v0.13.1/reference/foundations/dictionary/\">programming</a>\nlanguages, Typst provides a special type for <a href=\"/en-US-v0.13.1/reference/foundations/content/\"><em>content.</em></a> A value\nof this type can hold anything that you can enter into your document: Text,\nelements like headings and shapes, and style information.</p>\n<h2 id=\"example\">Example</h2>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">let</span> x <span class=\"typ-op\">=</span> <span class=\"typ-num\">10</span>\n<span class=\"typ-key\">#</span><span class=\"typ-key\">if</span> <span class=\"typ-func\">type</span><span class=\"typ-punct\">(</span>x<span class=\"typ-punct\">)</span> <span class=\"typ-op\">==</span> int <span class=\"typ-punct\">[</span>\n  <span class=\"typ-pol\">#</span><span class=\"typ-pol\">x</span> is an integer!\n<span class=\"typ-punct\">]</span> <span class=\"typ-key\">else</span> <span class=\"typ-punct\">[</span>\n  <span class=\"typ-pol\">#</span><span class=\"typ-pol\">x</span> is another value<span class=\"typ-escape\">...</span>\n<span class=\"typ-punct\">]</span>\n\nAn image is of type\n<span class=\"typ-func\">#</span><span class=\"typ-func\">type</span><span class=\"typ-punct\">(</span><span class=\"typ-func\">image</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;glacier.jpg&quot;</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">)</span>.\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/7538c768430ee75e747b4f97560d4ecf.png\" alt=\"Preview\"></div></div>\n<p>The type of <code>10</code> is <code>int</code>. Now, what is the type of <code>int</code> or even <code>type</code>?</p>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-func\">#</span><span class=\"typ-func\">type</span><span class=\"typ-punct\">(</span>int<span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">type</span><span class=\"typ-punct\">(</span>type<span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/1ea220672ff0a816e76e846567e22fe0.png\" alt=\"Preview\"></div></div>\n<h2 id=\"compatibility\">Compatibility</h2>\n<p>In Typst 0.7 and lower, the <code>type</code> function returned a string instead of a\ntype. Compatibility with the old way will remain until Typst 0.14 to give\npackage authors time to upgrade.</p>\n<ul>\n<li>Checks like <code>int <span class=\"typ-op\">==</span> <span class=\"typ-str\">&quot;integer&quot;</span></code> evaluate to <code><span class=\"typ-key\">true</span></code></li>\n<li>Adding/joining a type and string will yield a string</li>\n<li>The <code>in</code> operator on a type and a dictionary will evaluate to <code><span class=\"typ-key\">true</span></code>\nif the dictionary has a string key matching the type's name</li>\n</ul>","constructor":{"path":[],"name":"type","title":"Construct","keywords":[],"oneliner":"Determines a value's type.","element":false,"contextual":false,"deprecation":null,"details":"<p>Determines a value's type.</p>","example":"<div class=\"previewed-code\"><pre><code><span class=\"typ-func\">#</span><span class=\"typ-func\">type</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">12</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">type</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">14.7</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">type</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;hello&quot;</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">type</span><span class=\"typ-punct\">(</span><span class=\"typ-label\">&lt;glacier&gt;</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">type</span><span class=\"typ-punct\">(</span><span class=\"typ-punct\">[</span>Hi<span class=\"typ-punct\">]</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">type</span><span class=\"typ-punct\">(</span>x <span class=\"typ-op\">=&gt;</span> x <span class=\"typ-op\">+</span> <span class=\"typ-num\">1</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">type</span><span class=\"typ-punct\">(</span>type<span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.13.1/assets/3bff018780f2b4261ae9dc20c2e887a.png\" alt=\"Preview\"></div></div>","self":false,"params":[{"name":"value","details":"<p>The value whose type's to determine.</p>","example":null,"types":["any"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["type"],"scope":[]},"scope":[]}}}