Type 'string' is not assignable to type '{ name: never; weight: number; }'.
See original GitHub issueI get this error every time I test my app. Could you identify this error and solution?
Argument of type '{ shouldSort: boolean; threshold: number; location: number; distance: number;
maxPatternLength: n...' is not assignable to parameter of type 'FuseOptions<{}>'. Types of property
'keys' are incompatible. Type 'string[]' is not assignable to type 'never[] | { name: never; weight:
number; }[]'. Type 'string[]' is not assignable to type '{ name: never; weight: number; }[]'. Type 'string' is
not assignable to type '{ name: never; weight: number; }'.
The error occur on this line
const fuse = new Fuse(this.searchList, options)
in my line, this search is put in a function, that I will call it whenever I key anything in my input
filterQuery(val) {
const options = {
shouldSort: true,
threshold: 0.4,
location: 0,
distance: 100,
maxPatternLength: 16,
minMatchCharLength: 1,
keys: ["name"]
};
const fuse = new Fuse(this.searchList, options)
const results = this.sortList(fuse.search(val));
const newResult = [];
for (let i = 0; i < results.length; i++) {
newResult.push(results[i]);
if (i > 6) break;
}
this.filteredList = newResult;
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top Results From Across the Web
number' is not assignable to type 'never' in Typescript
Type 'string | number' is not assignable to type 'never'. Type 'string' is not assignable to type 'never'. It can work but not...
Read more >Type 'string' is not assignable to type 'never'.ts(2322)
this.collection.data.push(. {. id: i + 1, // here it gives error Type 'number' is not assignable to type 'never'.ts(2322). value: "items number "...
Read more >Type is not assignable to type 'never' in TypeScript | bobbyhadz
The error Type is not assignable to type 'never' occurs when we declare an empty array without explicitly typing it and attempt to...
Read more >TypeScript Fundamentals - Joy of Code
const pikachu = { name: 'Pikachu', weight: 60 } pikachu.weigth // oops! No ... toUpperCase() // Type 'number' is not assignable to type...
Read more >Chapter 2. Basic and custom types - TypeScript Quickly
TypeScript will complain: "Type '{ name: string; height: number; }' is not assignable to type 'Patient'. Property 'weight ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What I did was define a type for the items I’m passing in, and set that as the type of FuseOptions, and I was good.
@bkonkle as said in the comment right above yours please check the website on how to properly use Fuse.JS with TypeScript.
You need to split off the options to a separate constant and assign it the type of Fuse.FuseOptions<T> where T is a Generic Type that describes the list your searchinf