-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
Missing TypeScript types #26
Comments
I did some transformation of your annotations with vscode \* @property \{(.*)\} ([a-z]+) (.*) to
Will continue posting as I advance on this |
i'm absolutely against typescript :-) i haven't checked if there is a way to generate .d.ts because i have no need for them |
Yay 😄 .. type ItemCallback = (item: Object, inst: Autocomplete) => void;
type RenderCallback = (item: Object, label: string, inst: Autocomplete) => string;
type ServerCallback = (response: Response, inst: Autocomplete) => Promise
interface Config {
showAllSuggestions?: Boolean; // Show all suggestions even if they don't match
suggestionsThreshold?: Number; // Number of chars required to show suggestions
maximumItems?: Number; // Maximum number of items to display
autoselectFirst?: Boolean; // Always select the first item
ignoreEnter?: Boolean; // Ignore enter if no items are selected (play nicely with autoselectFirst=0)
updateOnSelect?: Boolean; // Update input value on selection (doesn't play nice with autoselectFirst)
highlightTyped?: Boolean; // Highlight matched part of the label
highlightClass?: String; // Class added to the mark label
fullWidth?: Boolean; // Match the width on the input field
fixed?: Boolean; // Use fixed positioning (solve overflow issues)
fuzzy?: Boolean; // Fuzzy search
startsWith?: Boolean; // Must start with the string. Defaults to false (it matches any position).
preventBrowserAutocomplete?: Boolean; // Additional measures to prevent browser autocomplete
itemClass?: String; // Applied to the 'li'. Accepts space separated classes.
activeClasses?: Array; // By default: ["bg-primary", "text-white"]
labelField?: String; // Key for the label
valueField?: String; // Key for the value
searchFields?: Array; // Key for the search
queryParam?: String; // Key for the query parameter for server
items?: Array | Object; // An array of label/value objects or an object with key/values
source?: Function; // A function that provides the list of items
hiddenInput?: Boolean; // Create an hidden input which stores the valueField
hiddenValue?: String; // Populate the initial hidden value. Mostly useful with liveServer.
datalist?: String; // The id of the source datalist
server?: String; // Endpoint for data provider
serverMethod?: String; // HTTP request method for data provider, default is GET
serverParams?: String | Object; // Parameters to pass along to the server. You can specify a "related" key with the id of a related field.
serverDataKey?: String; // By default: data
fetchOptions?: Object; // Any other fetch options (https://developer.mozilla.org/en-US/docs/Web/API/fetch#syntax)
liveServer?: Boolean; // Should the endpoint be called each time on input
noCache?: Boolean; // Prevent caching by appending a timestamp
debounceTime?: Number; // Debounce time for live server
notFoundMessage?: String; // Display a no suggestions found message. Leave empty to disable
onRenderItem?: RenderCallback; // Callback function that returns the label
onSelectItem?: ItemCallback; // Callback function to call on selection
onServerResponse?: ServerCallback; // Callback function to process server response. Must return a Promise
onChange?: ItemCallback; // Callback function to call on change-event. Returns currently selected item if any
}
declare module 'bootstrap5-autocomplete' {
export default class Autocomplete {
/**
* Attach to all elements matched by the selector
*/
public static init(selector: string, config: Config);
}
} Okay, then you can include a file with the types. Here is what I managed to do. |
it seems the proper way would be to generate that during the build process https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html |
Awesome 💯 , I can test the result for you if needed |
@williamdes have a look a2a7d87 |
Very cool, could you change all occurrences of |
PS: the README should probably say |
yes, the optional keys are kinda of annoying. the way i designed it, is that the full config object must have all the keys, but obviously you can also pass partial configs since they are going to be merged anyway. |
Only one could be enough I think, not sure if default values can be embed into an interface. |
@williamdes internally, they are all required by the class (values are expected to be set), but as an argument, you can pass anything |
closing this, if anyone has a good proposal to deal with partial config, i'm open to hear it, otherwise, as far as i'm concerned, i can live with how it's done :-) |
Hi 👋🏻
I found this library and it really seems interesting !
That said I use TypeScript with VueJS and it complains about the lack of .d.ts files.
Could you add a types file or would you be open to migrating to TypeScript (but still generating .js files) ?
The text was updated successfully, but these errors were encountered: