rdkcentral / Lightning-SDK

SDK for Lightning framework
Apache License 2.0
130 stars 69 forks source link

this.tag typescript issues #358

Closed eductech closed 1 year ago

eductech commented 2 years ago

Hi.

We spotted some issues during typescript usage .

Example:

interface ComponentSpec extends Lightning.Component.TemplateSpec {
    ExampleComponentChild: object;
}

class ExampleComponent
    extends Lightning.Component<ComponentSpec>
    implements Lightning.Component.ImplementTemplateSpec<ComponentSpec>
{
    static _template(): Lightning.Component.Template<ComponentSpec> {
        return {
            ExampleComponentChild: {},
        };
    }

    get ExampleComponentChild() {
        return this.tag('ExampleComponentChild');
    }
}

this.tag emits ts error:

Type instantiation is excessively deep and possibly infinite.ts(2589)

Package versions:

    "@lightningjs/core": "2.7.1",
    "@lightningjs/sdk": "5.1.0",
    "typescript": "4.8.3"

Let me know if I'm doing something wrong or if you need any other info.

michielvandergeest commented 2 years ago

@frank-weindel would you be able to take a look at this issue? Thanks!

frank-weindel commented 2 years ago

@eductech I tried reproducing your issue but was unable to. I've created a repo of my attempt so you can take a look: https://github.com/frank-weindel/lighnting-sdk-358-repro

Let me know if you have the problem even in that project.

eductech commented 1 year ago

@frank-weindel thanks for looking into it. Issue reported is not reproducible in case of your example.

I made use of yours package versions and yours ts config - to check if error will be still reproducible in case of my repo. Unfortunately it is still there.

frank-weindel commented 1 year ago

@eductech Please share a minimal reproduction of the issue if possible. We won't be able to derive the root cause of the issue without it.

eductech commented 1 year ago

@frank-weindel please check this https://github.com/eductech/lighnting-sdk-358-repro/tree/strict-false. This is fork of https://github.com/frank-weindel/lighnting-sdk-358-repro. The only thing changed on strict-false branch - strict: false was set in tsconfig.json

Sorry that it was not spotted at very beginning. This exactly what differs ts configuration from your example, and in this case error is reproducible.

UPDATE As we figured out strictNullChecks does the job. When it set to true - error disappears.

frank-weindel commented 1 year ago

Thanks @eductech for that repro! I've submitted a PR to update the documentation to hopefully avoid others from having this issue in the future. Let us know how the rest of your experience using TypeScript with Lightning continues to go. Cheers.