illright / attractions

A pretty cool UI kit for Svelte
https://illright.github.io/attractions
MIT License
1.03k stars 37 forks source link

Autocomplete: Property 'getOptions' does not exist on type 'IntrinsicAttributes & AutocompleteProps' #325

Closed ThomasOrlita closed 2 years ago

ThomasOrlita commented 2 years ago

I'm using the Autocomplete element, but TypeScript is complaining that the getOptions property doesn't exist.

image

Attractions 3.5.0 Svelte 3.44.2 TypeScript 4.5.2

aabounegm commented 2 years ago

Thank you for filing this issue. The problem was due to updating to a sveld without checking the changelog first 😅, which caused a type import (the one being extended by Autocomplete) to be invalid. A pull request fixing this issue is in progress.

aabounegm commented 2 years ago

The patch has been released with version 3.5.1. Please verify that the issue is indeed fixed.

ThomasOrlita commented 2 years ago

Thanks for the quick update!

Now it however lights up with a different error:

Type '(text: any) => AsyncGenerator<({ name: any; details: string; } | { name: string; details?: undefined; })[], void, unknown>' is not assignable to type 'OptionsGetter'.
  Property '[Symbol.iterator]' is missing in type 'AsyncGenerator<({ name: any; details: string; } | { name: string; details?: undefined; })[], void, unknown>' but required in type 'Generator<Promise<Option[]>, never, never>'.

This is the code (from the demo):

<script lang="ts">
  import { Autocomplete } from 'attractions';

  async function* getOptions(text) {
    yield [{ name: text, details: 'Optional' }, { name: `it highlights the match: ${text}` }];
  }
</script>

<Autocomplete getOptions={getOptions} />
aabounegm commented 2 years ago

Hmm. I'm not so familiar with generator functions' types, but do you think

type OptionsGetter = (q: string) => AsyncGenerator<Option[], void, void>;

would be more appropriate?

ThomasOrlita commented 2 years ago

Hmm. I'm not so familiar with generator functions' types, but do you think

type OptionsGetter = (q: string) => AsyncGenerator<Option[], void, void>;

would be more appropriate?

I think this type should work. 👍

aabounegm commented 2 years ago

Does release v3.5.2 fix the issue?

ThomasOrlita commented 2 years ago

Yes, it's fixed now. Thank you!