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

Pretty interesting, but it doesn't seem to be possible to use the resulting values? Except as type declarations of course. Also, the playground link either fails (there are several errors) or doesn't produce any output.


hover over the type annotations to see results in the playground, that's the output :)

The errors aren't really errors, just warnings about unused types


yeah Typescript is compile-time-only type system, you can only use it as a type. still cool though


But if you declare a string literal as const, then the string runtime value will match the string type. So it would be possible to have a runtime result (that executes an actual db query for example) that is paired with the type result.


No, TypeScript is compile time only. There's no runtime type info.


The parent comment is saying that if you write the string twice, you can get the compiler to check #1 and the runtime to use #2.


Not exactly (there is no duplication), a string constant in typescript is it's own type:

  const sql = 'SELECT ...';
  type SQL = typeof sql; 
  // type SQL = "SELECT ..."




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

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

Search: