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

Consider this  #35

@KATT

Description

@KATT

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions