Skip to content
This repository was archived by the owner on Dec 19, 2022. It is now read-only.

Consider this #35

Open
KATT opened this issue Apr 11, 2022 · 0 comments
Open

Consider this #35

KATT opened this issue Apr 11, 2022 · 0 comments

Comments

@KATT
Copy link
Member

KATT commented Apr 11, 2022

Tried to write a reply to this on my phone but too hard! Yes this is pretty much what I was thinking. A couple of ways it could be simplified even further occur to me tho:

  1. No linear generics at all. This might prove impossible if the compiler loses track of property types somewhere along the way, but here's a simplified example:
interface Params {
  input: unknown
  output: unknown
  context: unknown
}

const getClientThatUsesSpecificParams = <P extends Params>(params: P) => {
  return {
    useInput: (input: P['input']) => 123,
    getOutput: () => params.output,
  }
}

const specific = getClientThatUsesSpecificParams({
  input: {foo: 'abc'},
  output: [123, 456],
  context: {bar: 987},
})

TypeScript doesn't need specific typeargs for TInput, TOutput, TContext to keep track of them:

image

  1. Maybe there could be an IO type to generalise the _in and _out suffixes?
interface IO<I, O> {
  in: I
  out: O
}

interface Params< 
  TContextIn = unknown,
  TContextOut = unknown,
  TInputIn = unknown,
  TInputOut = unknown,
  TOutputIn = unknown,
  TOutputOut = unknown,
> {
  ctx: IO<TContextIn, TContextOut>
  input: IO<TInputIn, TInputOut>
  output: IO<TOutputIn, TOutputOut>
}
  1. Both together!?!!?
interface IO {
  input: unknown
  output: unknown
}

interface Params {
  ctx: IO
  input: IO
  output: IO
}

Originally posted by @mmkal in #33 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant