svelte-typeahead icon indicating copy to clipboard operation
svelte-typeahead copied to clipboard

Svelte-check error when using placeholder

Open beholdr opened this issue 1 year ago • 4 comments

Hello, I've got an error when run svelte-check if I’m using placeholder attribute on a Typeahead component:

<Typeahead placeholder="Text" />

Error: Object literal may only specify known properties, and '"placeholder"' does not exist in type 'TypeaheadProps<string | number | Record<string, any>>'. (ts)

beholdr avatar Jul 11 '24 16:07 beholdr

svelte-typeahead depends on svelte-search 1.1 which cause this type error. When I update typings in node_modules/svelte-search/types/Search.d.ts to:

- export interface SearchProps
-   extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["input"]> {
+ import type { HTMLInputAttributes } from "svelte/elements";
+
+ export interface SearchProps extends HTMLInputAttributes {

Then error is gone.

Maybe you can update svelte-typeahead dependency to current svelte-search version?

beholdr avatar Jul 12 '24 08:07 beholdr

As a workaround I found a way to please svelte-check with such hack:

<script lang="ts">
  import type { ComponentProps, ComponentType, SvelteComponent } from 'svelte'
  import Typeahead from 'svelte-typeahead'

  interface PropsWithPlaceholder extends ComponentProps<Typeahead> {
    placeholder?: string
  }
  const input: ComponentType<SvelteComponent<PropsWithPlaceholder>> = Typeahead
</script>

<svelte:component this={input} hideLabel placeholder="XXX" />

But it's better to fix this in svelte-search code.

beholdr avatar Jul 12 '24 08:07 beholdr

Thanks for reporting – agree that the svelte-search dependency upgrade is likely the culprit. Did you want to take a pass at this?

metonym avatar Jul 15 '24 14:07 metonym

I'm sorry, but I can't assist you with that at the moment. I have already selected another library because of issue #28.

beholdr avatar Jul 15 '24 16:07 beholdr

Fixed in v4.4.2

metonym avatar Nov 20 '24 17:11 metonym