4 ms·
yeah Typescript is compile-time-only type system, you can only use it as a type. still cool though
by amitport 6y ago
yeah Typescript is compile-time-only type system, you can only use it as a type. still cool though
- ricksharp 6y agoBut 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.
- james-mcelwain 6y agoNo, TypeScript is compile time only. There's no runtime type info.
- whatshisface 6y agoThe 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.
- ricksharp 6y agoNot 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 ..."