Settings

Theme

Ask HN: Resources on writing a parser in TypeScript's type system

1 points by PeledYuval 4 years ago · 0 comments · 1 min read


Hi HN, a niche Typescript+parsers question.

I'm looking for resources that will allow me to write a parser inside of Typescript's type system by leveraging template literal types.

Reasoning: I'm writing a Typescript library that allows compile-time checks for raw SQL queries. The goal is to allow compile time safety for queries without reliance on an ORM query builder or manually maintained type hints. It would look roughly like so:

  // some type of DB structure definition. This will definitely change
  const dbSchema = { person: {name: 'varchar', born_at: 'timestamptz' }};
  // Throws compile time error since "address" does not exist in "person" table
  query<typeof dbSchema>('SELECT address FROM person');
I have a (more complicated) POC of this here: https://github.com/Yuval-Peled/Tequel

Thanks in advance

EDIT: Punctuation

No comments yet.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection