tom-select icon indicating copy to clipboard operation
tom-select copied to clipboard

[Bug]: Typescript – TomCreate type does not match documented usage for `create` setting

Open CharlieIGG opened this issue 1 year ago • 0 comments

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

  1. Setup a project using Typescript
  2. Try to instantiate a new TomSelect with a function on the create setting:
      new TomSelect(this.element, {
            create: function (input) {
                return { value: input, text: input }
            }
        });

Additional context

"typescript": "^5.3.3" "tom-select": "^2.3.1",

CharlieIGG avatar Jan 20 '24 08:01 CharlieIGG