question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type 'string' is not assignable to type '{ name: never; weight: number; }'.

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
mithunm93commented, Mar 1, 2019

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.

interface ItemInterface {
  name: string
}

const items: ItemInterface[] = [{ name: "Mithun" }, ...];

const options: FuseOptions<ItemInterface> = {
  keys: ["name"],
};

const fuse = new Fuse(items, options);
2reactions
favnacommented, Mar 12, 2019

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found