Git Product home page Git Product logo

Comments (4)

vmasek avatar vmasek commented on June 7, 2024 1

It is possible to type the methods with generic types for example

go<T>(search: string, targets: (T | string | Prepared | undefined)[], options: KeysOptions): KeysResults<T>

with some changes to the results interfaces
KeysResults<T> would have the original obj with type user has passed to the search function

/** Your original object */
    readonly obj: T

I'll try to cover that in PR

from fuzzysort.

vmasek avatar vmasek commented on June 7, 2024

I managed to do the desired functionality when working on a #36, what seems to be a problem is the inaccurate typing for typescript.

is the index.d.ts autogenerated or do you write it yourself?
What seems to be a problem is that in cases of KeyResults adn KeysResults the targets parameter is (string | Prepared | undefined)[], but I would expect it to be ({ [key: string]: string } | undefined)[] which makes much more sense as you are passing a key indexable objects array.

Another more convinient solution would be to use type generics. I can prepare PR when I take a closer look on what is beeing returned in specific cases

from fuzzysort.

farzher avatar farzher commented on June 7, 2024

yeah, so, keys is the option you want.

and you're right about index.d.ts being messed up. it's not autogenerated. i'm a typescript noob.
(string | Prepared | undefined)[] is totally wrong, ({[k:string]:any} | undefined)[] would work. what's a generic? is that better?

from fuzzysort.

farzher avatar farzher commented on June 7, 2024

that sounds good

from fuzzysort.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.