svelte-scrollto-element icon indicating copy to clipboard operation
svelte-scrollto-element copied to clipboard

TS complains when passing a `string` element

Open rubenvar opened this issue 1 year ago • 2 comments

Hello, and thanks for forking svelte-scrollto and updating it.

I'm having some trouble using svelte-scrollto-element with TypeScript. I just followed the examples in the readme. The scrolling works totally fine, no problem there. But TS is not happy:

If I do it the action way (which is the one I prefer):

<a use:scrollto={'#images'}>Images</a>

I get this TS error:

Type '"#images"' has no properties in common with type 'ScrollToElementOptions'.

I guess it is expecting a ScrollToElementOptions object, but I'm passing just a string. Should we update the action to accept a string too?

And if I do it the programmatically way:

<a on:click={() => animateScroll.scrollTo({element: '#images'})}>Images</a>

I get this one:

Type 'string' is not assignable to type 'HTMLElement'.

In this case, I see that ScrollToElementOptions.element expects a HTMLElement, but as per the example I'm passing just a string too. Should we change ScrollToElementOptions.element to expect a string?

Am I not getting something, or should I do it another way?

rubenvar avatar Feb 19 '23 23:02 rubenvar