ractivejs/ractive

New typescript errors: Type instantiation is excessively deep and possibly infinite

Closed this issue · 4 comments

Description:

I just tried to use Ractive 1.4.2 and its typings with typescript 4.8.4 - 5.1.3 and was stopped by the following error message:

TS2589: Type instantiation is excessively deep and possibly infinite.

Versions affected:

  • Ractive 1.4.2
  • Typescript versions at least (4.8.4 - 5.1.3)

Reproduction:

The code he seems to be complaining about is this:

const TestComponent = Ractive.extend({ });

var SearchView: Ractive = new Ractive({
    components: { TestComponent },
    target: document.querySelector('main'),
    data: function() {
        return {};
    },
    template: `
        <TestComponent></TestComponent>
    `
});

More specifically, he complains about the components field in Ractive's ctor parameters. That field is defined as:

components?: Registry<Component>;
// where Component is:
type Component = Static<any> | Promise<Static<any>>;

All of the self-references in the types Static, Ractive, and PropertyOptsare a little over my head right now. A quick fix I found is changing the components-field definition to:

components?: Registry<any>;

I'm getting the same things on same versions. Would like to know why.

I think this is one of the type gymnastics that isn't super well supported by TS. It used not to complain about it, but I think somewhere around 4.0 something changed with recursive types. It's not technically wrong, but the compiler complains about it now. It probably would be ok to swap it over to Registry and just lose checking for putting non-components in the component registry.

It should be better with 1.4.3, yes.