tom-select
tom-select copied to clipboard
[Bug]: Typescript – TomCreate type does not match documented usage for `create` setting
Bug description
The documentation provides the following function assignment for the create setting:
create: function(input){
return {value:input,text:input}
}
create: function(input,callback){
callback({value:input,text:input});
}
However, when trying to use any of these with Typescript, the type checker complains:
Type '(input: string) => { value: string; text: string; }' is not assignable to type 'boolean | TomCreate | undefined'.
Inspecting the TomCreate type:
export type TomCreate = (input: string, create: TomCreateCallback) => boolean;
Note how this is in direct conflict with the documented usage, since the docs indicate an object should be returned, whereas the type indicates that a boolean should be returned.
Expected behavior
The documentation and the type should match. Potentially, this means that the type might need to be adjusted?
Steps to reproduce
- Setup a project using Typescript
- Try to instantiate a new TomSelect with a function on the
createsetting:
new TomSelect(this.element, {
create: function (input) {
return { value: input, text: input }
}
});
Additional context
"typescript": "^5.3.3" "tom-select": "^2.3.1",