Create many generic types with similar shape

85 Views Asked by At

I'd like to create a TypeScript generic, that creates a type for me which has a generic input with a (extends) constraint. I don't want to specify the constraint everywhere since I want to create a lot of types with a similar shape.

I want something like this (kinda pseudocode)

type CreateMyType<A extends Constraint> = ...

type MyCustomType = CreateMyType<A>

MyCustomType<T> // T can only extend Constraint without specifying here

Is this possible? I though of maybe with infer keyword and never, but I want the autocompletion also to work for the type parameter of MyCustomType.

Any tips to accomplish a similar behavior?

0

There are 0 best solutions below