2

given the following example:

type V0Input = {
  version: '0'
};

type V1Input = {
  version: '1'
}

type AnyInput = V0Input | V1Input;

type V0Output = {
  a: string
}

type V1Output = {
  b: string
}

type Ret<I> = I extends V0Input ? V0Output : V1Output

const fn = <I extends AnyInput>(i: I): Ret<I> => i.version === '0' ?
  {a: ''} as Ret<I> :
  {b: ''} as Ret<I>
;

Did anyone found out a way to remove those casts? I've started using something like that without casts (taking lambda parametrized by outer I), but it turns out that my method doesn't work for all kind of objects.

4

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.