Skip to content
DevMeme
5843 of 7590
Interviews Post #6396 · source on Telegram

Solving algorithms with TypeScript's type system

Description

This image is a screenshot of a tweet by user 'zack (in SF)' (@zack_overflow), parodying a previous meme format. The tweet reads: 'The most bizarre coding interview I've ever done was at Facebook when as usual I asked a candidate to write in any language of their choice.. And they nonchalantly said "I'll write it in Typescript types", to which I almost let loose a chuckle until...'. Below the text is a snippet of TypeScript code in a dark-themed editor. The code is not typical runtime logic but is instead a complex, recursive type definition named 'MovePipesImpl'. It uses advanced features like generics, conditional types, and the 'infer' keyword, demonstrating type-level programming. The humor comes from the extreme and unexpected application of TypeScript's type system to solve a problem, a flex that demonstrates deep, esoteric knowledge. For senior engineers, it's a nod to the Turing-completeness of modern type systems and the kind of wildly clever, impractical solution that is both horrifying and impressive

Comments

7
Anonymous ★ Top Pick The candidate's code has zero runtime exceptions, zero dependencies, and can calculate the heat death of the universe, but only if the answer is a type
  1. Anonymous ★ Top Pick

    The candidate's code has zero runtime exceptions, zero dependencies, and can calculate the heat death of the universe, but only if the answer is a type

  2. Anonymous

    I got worried when the entire game loop ran in conditional types - ship that to prod and our runtime becomes tsc and our pager is the compiler’s recursion-depth error

  3. Anonymous

    When you've spent so long arguing that TypeScript isn't a real programming language, you accidentally prove it's Turing complete at compile time while trying to make a point

  4. Anonymous

    When the interviewer said 'any language,' they probably weren't expecting a candidate to implement Flappy Bird in TypeScript's type system - a Turing-complete language where the 'runtime' is the compiler and your bugs manifest as 'Type instantiation is excessively deep and possibly infinite.' It's the ultimate power move: writing code that executes during compilation, ensuring your game logic is verified before a single line of JavaScript runs. The real question is whether the candidate's solution passed in O(compile-time) or if the TypeScript compiler needed a coffee break to resolve those nested conditional types

  5. Anonymous

    If your candidate can write Flappy Bird in TypeScript's type system, congrats - you just moved the runtime into the compiler and your latency into tsc

  6. Anonymous

    Nothing like discovering your “any language” policy includes a Turing-complete type system - runtime O(0), compile time O(nested_conditional_types), and tsc is now the VM

  7. Anonymous

    TypeScript at Meta: solving runtime problems at compile time, one infer at a time - until the types themselves need filtering

Use J and K for navigation