Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Next, let's go to the frontend … const user = cast<User>(userJson);

Wait, how can Deepkit's `cast` work on the frontend? Do you compile to WASM?

Quickly skimming the current Deepkit homepage and intro blog post didn't seem to hint at this.



It makes the types available in runtime. You can take a look at the current WIP version of the new upcoming Deepkit book which explains it in great detail: https://deepkit-book.herokuapp.com See section "2. Runtime Types"


Thanks – the question I had was answered in the "Bytecode" part of that section: https://deepkit-book.herokuapp.com/deepkit-book-english.html...

My summary is that the DeepKit compiler is a JS transpiler (used as a ts-node or webpack plugin, or conveniently/invasively as a replacement of node_modules/typescript) that produces code like this:

    //TypeScript
    export type TypeA = string[];

    //generated JavaScript
    export const __ΩtypeA = ['&F'];

    //TypeScript
    function log(message: string): void {}

    //generated JavaScript
    function log(message) {}
    log.__type = ['message', 'log', 'P&2!$/"'];
Where '&F' and 'P&2!$/"' are the compact bytecode translations of the types ("&" means string, "F" means array) and '__Ω' is a prefix used to avoid naming conflicts.

Personally, I'd love to see a live example of code in & compiled code out on the homepage. I'm sure it's on your roadmap :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: