<story><title>TypeScripts Type System Is Turing Complete</title><url>https://github.com/Microsoft/TypeScript/issues/14833</url></story><parent_chain></parent_chain><comment><author>Gehinnn</author><text>When I discussed my discovery with a friend of mine who is doing his PhD, he was not really excited about it and once I showed him the features of TypeScripts typesystem, he immediately explained me why it has to be turing complete.
So in theory, this result is nothing new and nothing &amp;quot;newsworthy&amp;quot;.&lt;p&gt;However, even being myself a CS student close to finishing my BA degree and stronlgy interested in CS theory, I didn&amp;#x27;t know that result and I couldn&amp;#x27;t imagine how powerful TS&amp;#x27;s typesystem is. So, there actually are a lot of people who underestimate the power of typescripts typesystem completely and who could write even safer code if they knew about it.&lt;p&gt;I don&amp;#x27;t know exactly anymore how I &amp;quot;rediscovered&amp;quot; this turing-completeness-property, but at that time I was developing a &amp;quot;fully&amp;quot; typed SQL builder as an alternative to knex (&lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;hediet&amp;#x2F;ts-typed-sql&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;hediet&amp;#x2F;ts-typed-sql&lt;/a&gt;) and did some research on how to make certain SQL constructs typesafe in TypeScript.
For example, one thing I needed, was a type RecordTypeToJson&amp;lt;T&amp;gt; which could recursively transform a sql record type T to a proper json type: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;hediet&amp;#x2F;ts-typed-sql&amp;#x2F;blob&amp;#x2F;master&amp;#x2F;src&amp;#x2F;AST&amp;#x2F;Types.ts#L68&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;hediet&amp;#x2F;ts-typed-sql&amp;#x2F;blob&amp;#x2F;master&amp;#x2F;src&amp;#x2F;AST&amp;#x2F;T...&lt;/a&gt;&lt;p&gt;Without the devices discovered in the TC-proof I wouldn&amp;#x27;t have been able to implement that particular type. And once I recognized the power of TS, I found some other useful devices, e.g. how to use overloading to report custom error messages for invalid types (&lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;hediet&amp;#x2F;ts-typed-sql&amp;#x2F;blob&amp;#x2F;master&amp;#x2F;src&amp;#x2F;AST&amp;#x2F;Queries&amp;#x2F;SelectQuery.ts#L89&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;hediet&amp;#x2F;ts-typed-sql&amp;#x2F;blob&amp;#x2F;master&amp;#x2F;src&amp;#x2F;AST&amp;#x2F;Q...&lt;/a&gt;) or how to track whether more than one column is selected (&lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;hediet&amp;#x2F;ts-typed-sql&amp;#x2F;blob&amp;#x2F;master&amp;#x2F;src&amp;#x2F;AST&amp;#x2F;Queries&amp;#x2F;SelectQuery.ts#L57&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;hediet&amp;#x2F;ts-typed-sql&amp;#x2F;blob&amp;#x2F;master&amp;#x2F;src&amp;#x2F;AST&amp;#x2F;Q...&lt;/a&gt;).&lt;p&gt;I hope that these ideas inspire other libraries as well!</text></comment>
<story><title>TypeScripts Type System Is Turing Complete</title><url>https://github.com/Microsoft/TypeScript/issues/14833</url></story><parent_chain></parent_chain><comment><author>lopatin</author><text>Gotta mention Shen here, the language with an intentionally Turing complete type system. You can write your types as Horn clauses.&lt;p&gt;&lt;a href=&quot;http:&amp;#x2F;&amp;#x2F;shenlanguage.org&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;shenlanguage.org&amp;#x2F;&lt;/a&gt;</text></comment>