Skip to content

Instantly share code, notes, and snippets.

@clockworkgr
Created December 11, 2023 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clockworkgr/20743c9cd351ea37ae75bfa520b19da1 to your computer and use it in GitHub Desktop.
Save clockworkgr/20743c9cd351ea37ae75bfa520b19da1 to your computer and use it in GitHub Desktop.

Task description:

Assume you have the following files:

query1.ts

type Args = {
 arg1: number,
 arg2: string
}
type ReturnVal = {
  value: string
}

function getStringData(args: Args): ReturnVal {
  return { value: "Returned" }
}

query2.ts

type Args = {
 arg1: string,
 arg2: number
}
type ReturnVal = {
  value: boolean
}

function getBooleanData(args: Args): ReturnVal {
  return { value: true }
}

Also assume there could be more queryX.ts files similar to this.

Implement a TS class (let's call it Querier) that can be configured with 1 or more of those queries in such a way where:

const results = querier.query1.getStringData(args);

and/or

const results = querier.query2.getBooleanData(args);

etc.

are available, typed appropriately and with code-completion working.

You are free to make any appropriate modifications to the query files.

Bonus:

Make output of the queryX functions vary based on a configuration variable of the querier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment