Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript error : Type 'HTMLElement | null' is not assignable to type 'string | HTMLElement | undefined'. #828

Closed
messenjer opened this issue Mar 1, 2024 · 5 comments · Fixed by #833

Comments

@messenjer
Copy link
Contributor

Overview of the problem

Oruga version: 0.8.5
Vuejs version: 3.4.19
OS/Browser:

Description

When I upgrade to oruga 0.8, I have a typescript error.

Steps to reproduce

src/pages/MyPage.vue:260:49 - error TS2322: Type 'HTMLElement | null' is not assignable to type 'string | HTMLElement | undefined'.

260 const loadingComponent = oruga.loading.open({ container: eltRef.value });

Expected behavior

As in the documentation, you must be able to have container === null

setTimeout(() => loadingComponent.close(), 3 * 1000);

function openLoading() {
    const loadingComponent = oruga.loading.open({
        fullPage: isFullPage.value,
+        container: isFullPage.value ? null : elementRef.value,
    });
    setTimeout(() => loadingComponent.close(), 3 * 1000);
}

Actual behavior

error TS2322: Type 'HTMLElement | null' is not assignable to type 'string | HTMLElement | undefined'.

@mlmoravek mlmoravek added the bug Something isn't working label Mar 1, 2024
@mlmoravek
Copy link
Member

Sorry, I can't reproduce this type error :/

@messenjer
Copy link
Contributor Author

No worries, thanks for Oruga ;-)

@mlmoravek mlmoravek added can't reproduce and removed bug Something isn't working labels Mar 2, 2024
@messenjer
Copy link
Contributor Author

Sorry, I didn't see that you'd changed your comment, after I replied. I've got the error in my project, I'll look into making a reproduction.

@messenjer
Copy link
Contributor Author

messenjer commented Mar 11, 2024

Hello,

I've updated a branch of my project where I'm testing the version 0.8 of bulma to the new version 0.8.6.

I have fewer errors.

However, I still get this error in vscode, or with vue-tsc.

Here are some screenshots.

The type of oruga.loading.open: (method) open(params: ProgrammaticProps): ProgrammaticExpose

Screenshot 2024-03-11 at 14 43 12

The error:

Screenshot 2024-03-11 at 14 43 32

I think a solution would be to change the container type here to accept null.

https://github.com/oruga-ui/oruga/blob/134a72ce0acfda00a4ac1aa288de4b10ca2d242d/packages/oruga/src/components/loading/Loading.vue#L69C1-L72C7

    /**
     * DOM element where the loading component will be created on (for programmatic usage).
     * Note that this also changes fullPage to false.
     */
    container: {
-        type: [Object, String] as PropType<string | HTMLElement>,
+        type: [Object, String] as PropType<string | HTMLElement | null>,
        default: () => getOption("loading.container", "body"),
    },

I cannot reproduce it in a simple example.

But I think there is an issue in my repro because, the type of oruga.loading.open is (method) open(params: Readonly<any>): ProgrammaticExpose with a Readonly<any> instead of ProgrammaticProps

My repro : https://stackblitz.com/~/github.com/messenjer/oruga-typeerror

Regards

Mathieu

@mlmoravek
Copy link
Member

@messenjer Try deleting the node_modules folder, the package-lock.json, reinstalling all dependencies and then restarting your ide. This solves the any as type problem for me.
And also try to update vue-tsc and and the volar extension.

However, i will consider adding null to the container prop type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants