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.

[Typescript Question] what is the way to use this library with typescript?

See original GitHub issue

Hi, I am trying to use this library in my typescript project but couldnā€™t figure it out how. here is my code that is working:

import Fuse from "fuse.js";
const fuse = new Fuse(metaData, {
    keys: [
      { name: "title", weight: 0.3 },
      { name: "tags", weight: 0.7 }
    ]
  });
const result = fuse
            .search(inputValue)
            .find(el => el.item.key === 'something');

but at last line itā€™s getting me error: Property 'item' does not exist I know the code is correct because it is working with // @ts-ignore` but whatā€™s wrong with typing?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
kriskcommented, Mar 21, 2020

Iā€™ll add examples to the docs. But something like this:

// Requires --esModuleInterop compiler flag
// import * as Fuse with '--allowSyntheticDefaultImport'
// or import Fuse = require('fuse.js') with neither
import Fuse from 'fuse.js';

type SimpleBookFuse = {
    title: string;
    author: {
        firstName: string;
        lastName: string;
    };
    tags: string[]
};

const books: SimpleBookFuse[] = [{
  'title': "Old Man's War",
  'author': 'John Scalzi',
  'tags': ['fiction']
}, {
  'title': 'The Lock Artist',
  'author': 'Steve',
  'tags': ['thriller']
}]

const options: Fuse.FuseOptions<SimpleBookFuse> = {
  keys: ['author', 'tags'],
};
const fuse = new Fuse(books, options)
const results = fuse.search('tion')
2reactions
saostadcommented, Mar 24, 2020

I updated to v 5.0.9-beta and itā€™s working šŸ‘ thank you so much!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Library Structures - TypeScript
Identifying the structure of a library is the first step in writing its declaration file. We'll give hints on how to identify structure...
Read more >
How to use a library in typescript - Stack Overflow
I am learning typescript. Faced the problem of connecting the axios library. File main.ts /// <reference path=".
Read more >
How to build a React library using TypeScript - Prateek Surana
A step by step guide to setup a React Library from scratch using TypeScript, and publish it to NPM.
Read more >
Integrate a UI5 library in a UI5 app using TypeScript | SAP Blogs
In this blog post I would like to share an approach how to run your TypeScript app and library together in your IDE....
Read more >
[Question] Can't have a "pure" typescript library. #5225 - GitHub
So we have several libraries written fully in TypeScript. If I understand correctly, we can't make simple import { smth } from 'pure-ts-lib/someĀ ......
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