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 - Object is unknown when calling on:"event" for external library child component that is JS #533

Closed
MDoder97 opened this issue Sep 10, 2020 · 3 comments
Labels
question Further information is requested

Comments

@MDoder97
Copy link

MDoder97 commented Sep 10, 2020

Describe the bug

This is a similar error as this closed issue - #396
I think the only difference is that the plainJS component is used in that one.
I've tried in multiple ways to recreate how the person who opened that one has solved it but to no avail.
I have a Svelte Material UI Slider

I import it like this

import Slider from '@smui/slider/bare.js';

this is the problematic line - <Slider on:volume-changed={event => changeTrackVolume(event, track)}/>

If i add in my types.d.ts

declare module '@smui/slider/bare.js' {
    export class Slider {
        $$prop_def: any;
        $on: any;
    }
}
Object is of type 'unknown'.ts(2571)
Argument of type 'typeof import("@smui/slider/bare.js")' is not assignable to parameter of type 'AConstructorTypeOf<unknown>'.
  Type 'typeof import("@smui/slider/bare.js")' provides no match for the signature 'new (...args: any[]): unknown'.ts(2345)

JSX element type 'Slider' does not have any construct or call signatures.ts(2604)

These are the errors i'm getting.
I have also tried with @smui/slider etc. and export default Slider, nothing worked so far.

I'd appreciate if someone could cue me in.

Thanks.

@MDoder97 MDoder97 added the bug Something isn't working label Sep 10, 2020
@jasonlyu123
Copy link
Member

jasonlyu123 commented Sep 11, 2020

you can try adding constructor to the Slider class definition

@dummdidumm
Copy link
Member

declare module '@smui/slider' {
  export default class Slider {
    $$prop_def: any;
    $on: any;
  }
}

then import like
import Slider from '@smui/slider';
works for me.

If that doesn't fix it, could you post a reproducible code snippet+step-by-step or a repo?

@MDoder97
Copy link
Author

@dummdidumm that worked lol, that's probably about the only thing i didn't try, so elusive.

Thanks alot!

@jasonlyu123 jasonlyu123 added question Further information is requested and removed bug Something isn't working labels Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants