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

This doesn't help in your case, but this is what GraphQL was invented for.

TS libraries for GQL queries can dynamically infer the response shape from the shape of the selected fields.

Such that the query

    query {
        user {
            username
            posts {
                text
            }
        }
    }
Would be

    type Response = {
        user: {
            username: string
            posts: Array<{
                text: string
            }>
        }
    }
And a query with just { user { username } } would have the posts property omitted entirely.


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

Search: