Skip to content

Type transformations do not use concrete types #37401

Closed
@aloifolia

Description

@aloifolia

So, I am not quite sure if there is already a way around this behaviour or if this is a feature request.

My code makes heavy use of type computations via recursive conditional types and mapped types. These types generate stuff like

// VSCode shows that Generated resolves to { a: { b1: { c: 42 }, b2: { d: { e:  42}}}}
type Generated = ComplicatedTransformation<SomeType> 

This works until I make use of these generated types by transforming them even further. E.g., there is

type OmitNever<T> = Omit<T, SelectKeys<T, never>>;

As soon as I feed the generated type Generated to OmitNever the compiler shows the infamous error message Type instantiation is excessively deep and possibly infinite (#31619).

Now I was wondering why the compiler does not use the concrete type that VSCode shows when the cursor hovers over Generated. Instead it seems to recalculate the whole (or part) of ComplicatedTransformation.

Is there a way to tell the compiler "use the generated type as is and just forget how this type was generated"? If not, would that be a useful addition (in my eyes it looks like that, but maybe I am missing something crucial)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs More InfoThe issue still hasn't been fully clarified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions