4 ms·
You can do some truly silly things with sufficiently ridiculous uses of typescript. I built a typecheck-time spell checker[0] in it such that: import { Vali
by fishtoaster 4y ago
You can do some truly silly things with sufficiently ridiculous uses of typescript. I built a typecheck-time spell checker[0] in it such that:
import { ValidWords } from "./spellcheck";
// Typechecks cleanly:
const result: ValidWords<"the quick brown fox."> = "valid";
// Throws a type error
const result: ValidWords<"the qxick brown fox."> = "valid";
[0] https://github.com/kkuchta/TSpell https://github.com/kkuchta/TSpell
- idontwantthis 4y agoSo does spellcheck contain a gigantic array of the English language?
- jjtheblunt 4y agothe source code to answer your question is directly above your question
- KMag 4y agoI'm inclined to cut someone a bit of slack for not following the link to the implementation if the context suggests deeply nested template meta programming golf is involved. It's surprisingly much less complicated than I would have expected.
- xdennis 4y agoYes. It looks like this: export type ValidWords<T extends string> = T extends "" ? "valid" : T extends `the${infer Rest}` | `of${infer Rest}` | `and${infer Rest}` | ...
- joshuakgoldberg 4y agoThis is great!
- spaetzleesser 4y agoHow long does this take to compile?
- fishtoaster 4y agoSomething like 40 seconds for a 9-word sentence. Would not recommend in production. :)
- gernb 4y agoso that's great and I know this wasn't your point but .... I use this VSCode extension https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker https://marketplace.visualstudio.com/items?itemName=streetsi... To spell check my code. It's surprisingly useful. It doesn't check at compile time but it does check camelCase and snake_case and even in typescript code I've found it highlight various actual issues.
- metadat 4y agoWhat do you do when a colleague has made the spelling error in the pasta? Open a PR?
- deleted 4y ago[deleted]
- kretaceous 4y agoYour GitHub account is a rabbit hole of crazy interesting "monstrosities" like this. I love them! My favorite ones, apart from this typechecker, are css-only-chat[1] and tabdb[2] 1: https://github.com/kkuchta/css-only-chat https://github.com/kkuchta/css-only-chat 2: https://github.com/kkuchta/tabdb https://github.com/kkuchta/tabdb