ractivejs / ractive

Next-generation DOM manipulation
http://ractive.js.org
MIT License
5.94k stars 396 forks source link

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

Closed seijikun closed 8 months ago

seijikun commented 1 year ago

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:

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>;
dedupely commented 1 year ago

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

evs-chris commented 1 year ago

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.

dedupely commented 8 months ago

Is this pushed to the latest version? It still does not work for me.

On Wed, Mar 13, 2024 at 6:23 PM Chris Reeves @.***> wrote:

Closed #3425 https://github.com/ractivejs/ractive/issues/3425 as completed via a6e1241 https://github.com/ractivejs/ractive/commit/a6e1241df60646db6b6bd764f35aeedc123488fc .

— Reply to this email directly, view it on GitHub https://github.com/ractivejs/ractive/issues/3425#event-12110647618, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHF3S74QQD46CJEHRZNWTXTYYDUXZAVCNFSM6AAAAAAYZ7V2FSVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJSGEYTANRUG43DCOA . You are receiving this because you commented.Message ID: @.***>

-- Clinton Skakun Founder & CEO Dedupely https://dedupe.ly/

+1-800-536-8156 @.***

evs-chris commented 8 months ago

It should be better with 1.4.3, yes.