escalier-lang / escalier

A compile-to-JavaScript language with tight TypeScript integration.
https://escalier-lang.github.io/escalier/
MIT License
21 stars 1 forks source link

Allow custom inference of string literals and tagged template literals #86

Open kevinbarabash opened 2 years ago

kevinbarabash commented 2 years ago

One use case for string literals would be routing, e.g.

<Route 
   path="/user/:id/:entity(posts|comments)"
   render={(params) => ...}
/>

could be used to correctly type params as {id: string, entity: "posts" | "comments"} automatically.

Tagged literals such as:

const query = gql`query HeroNameAndFriends {
  hero {
    name
    friends {
      name
    }
  }
}`

could return a GqlOpertaion<TData, TVariables> type where TData and TVariables are inferred with the correct types based on the operation inside the gql tagged template literal and the corresponding schema.

kevinbarabash commented 2 years ago

Another use case is document.querySelector and document.querySelectorAll.

kevinbarabash commented 1 year ago

We might also want a way to declare a type Pathname that admits all strings that are valid pathnames. Being able to parse a string in such a way that we can return an object type with the URL params is more powerful.