Giter Site home page Giter Site logo

TypeScript for Typesense? about typesense-js HOT 31 OPEN

typesense avatar typesense commented on June 15, 2024 18
TypeScript for Typesense?

from typesense-js.

Comments (31)

michaelbromley avatar michaelbromley commented on June 15, 2024 8

Having the lib in TS would be amazing - so far the slowest part of working with Typesense is the time taken to keep checking the docs to find out what methods I need to call on the client (plus the time debugging the errors caused by me assuming an incorrect return type etc).

In the meantime, I knocked together some type defs myself to make my own work more productive. Might be helpful for others until official TS support lands:

https://gist.github.com/michaelbromley/fd1e6137485200654cb7104439e6a699

from typesense-js.

dharijanto avatar dharijanto commented on June 15, 2024 8

I just wanna shout my thanks to @Ziao for your work :) I'm happily using typesense-js off your branch and it's working great. I really appreciate it!

from typesense-js.

Ziao avatar Ziao commented on June 15, 2024 6

@phihochzwei and everyone else,

I completed the TS conversion a while ago and updated the tests but never got around to getting the PR rebased and merged in. I'm very sorry to say that the work pressure is not allowing me to spend too much time on this at the moment, but essentially once any conflicts are solved and the work is reviewed, I'm cool having the PR merged in.

Here's the PR, btw: #62

from typesense-js.

jasonbosco avatar jasonbosco commented on June 15, 2024 6

Hey everyone,

Thanks to @Ziao and @dcantu476, we now have TypeScript types in v1.0.0-1 v1.0.0-3 .

There are no other breaking changes to the external API other than the switch to TypeScript. It felt like a big enough change to warrant a major version increment.

Would love to get your feedback!

from typesense-js.

jasonbosco avatar jasonbosco commented on June 15, 2024 5

Hey everyone, I need to update PR #43 to include types for the latest features available in Typesense. We're also working on v0.19 currently, which will have additional features. Once that's out in the coming weeks, I'll be able to focus on updating the PR.

In the meantime, I could definitely use some help on this, since I need to pick up Typescript on the fly.

from typesense-js.

Ziao avatar Ziao commented on June 15, 2024 4

I had a look at that PR, while a good start, it's generated from the JS source files and thus contains a lot of any types, exposes private members (starting with _), and would be a monster keeping it synchronised with the actual source code while also providing high quality typings. As @goleary mentioned, using typescript instead of javascript would alleviate a lot of headaches, both now and in the future when things get out of sync.

Would you be okay with a PR where I convert the entire code base into Typescript (while ensuring the tests still pass, of course)? It's not as scary as it sounds, but would ensure that things stay in sync in the future, and you get amazing code completion in your editor. I don't think this project is under heavy development right now, so I think it wouldn't cause too many issues. I'd be happy picking this up short term. Is there a way to contact you directly, such as Discord or similar?

from typesense-js.

WatanabeThiago avatar WatanabeThiago commented on June 15, 2024 4

up

from typesense-js.

jasonbosco avatar jasonbosco commented on June 15, 2024 4

@Ziao - I really appreciate the amount of effort you've put into shaping this PR! ๐Ÿ™

@dcantu476 and I have been working on getting your PR up to date and adding in some remaining types as part of #71.

from typesense-js.

jasonbosco avatar jasonbosco commented on June 15, 2024 4

Thanks @dcantu476. I've released this in v1.0.0-4.

from typesense-js.

jasonbosco avatar jasonbosco commented on June 15, 2024 1

@Ziao I missed Github's notification somehow.

Thank you for reviewing. It would be great to have a PR that converts the entire codebase to Typescript โค๏ธ

I made some tiny changes in the ts-server-0.20.0-support branch and I'll be merging that to master soon. Could you branch off of that for this PR?

from typesense-js.

dcantu476 avatar dcantu476 commented on June 15, 2024 1

@p-young I believe you are correct, but I'll have to test it more to be sure. I also think the correct type is logger.LogLevelDesc.

In the future, it might be better to implement some abstraction around the logger so that the client doesn't have to worry about using types directly from the logger library. It'd also put it in a good place where if you need to swap the logger out for something else in the future.

from typesense-js.

stephanoparaskeva avatar stephanoparaskeva commented on June 15, 2024

+1 would also love to see TS support

from typesense-js.

g5becks avatar g5becks commented on June 15, 2024

Really wouldn't be hard to write the definitions for it if the code had proper jsDocs.

from typesense-js.

jasonbosco avatar jasonbosco commented on June 15, 2024

I've personally not used Typsescript before, so I'd have to do some reading to get up to speed. Would love some help from more experienced Typescript experts!

from typesense-js.

jasonbosco avatar jasonbosco commented on June 15, 2024

Related: PR #43

from typesense-js.

Nick-Mazuk avatar Nick-Mazuk commented on June 15, 2024

Any updates on this? It looks the PR is done and ready to merge.

from typesense-js.

orlando avatar orlando commented on June 15, 2024

Hey @jasonbosco,

Any update on the TypeScript typings. We are evaluating search solutions at this moment for a new product and this is a great feature to have

from typesense-js.

Ziao avatar Ziao commented on June 15, 2024

I would be completely happy to pick this up and maintain it or if you need a hand with anything :)

from typesense-js.

jasonbosco avatar jasonbosco commented on June 15, 2024

@Ziao Thank you! That would be awesome!

I just started reading up on Typescript last week, but I could definitely use help with this. Would you be able to review PR #43? It's also missing the multi_search endpoint we added in v0.19. If you could help review + add types for the new endpoints, we can then merge that in.

from typesense-js.

jasonbosco avatar jasonbosco commented on June 15, 2024

Oh also, hereโ€™s our Slack channel: https://join.slack.com/t/typesense-community/shared_invite/zt-mx4nbsbn-AuOL89O7iBtvkz136egSJg

from typesense-js.

jasonbosco avatar jasonbosco commented on June 15, 2024

Thank you for that @michaelbromley!

CC: @Ziao

from typesense-js.

phihochzwei avatar phihochzwei commented on June 15, 2024

Any news on this? We urgently need this to use Typesense in our Firestore-Projects.

from typesense-js.

Ziao avatar Ziao commented on June 15, 2024

@jasonbosco @dcantu476 Woohoo! Nice one! I'll try to give it a spin this weekend and go through the changes one last time. Looks good though!

from typesense-js.

jasonbosco avatar jasonbosco commented on June 15, 2024

Released a new version v1.0.0-2 with the feedback in #73.

from typesense-js.

p-young avatar p-young commented on June 15, 2024

I gave it a try and ran into this error:

node_modules/typesense/lib/Typesense/Configuration.d.ts:31:16 - error TS2503: Cannot find namespace 'logger'.

31 logLevel?: logger.LogLevel;

At the top of Configuration.ts, should it be:
import * as logger from 'loglevel'

instead of right now:
import logger from 'loglevel'

The default export of loglevel doesn't seem to be the right thing.

from typesense-js.

jasonbosco avatar jasonbosco commented on June 15, 2024

Released a new version with improvements: https://github.com/typesense/typesense-js/releases/tag/v1.0.0-3

@dcantu476 The only other pending thing is: #32 (comment)

from typesense-js.

dcantu476 avatar dcantu476 commented on June 15, 2024

@jasonbosco I'll do a small PR for the loglevel typings and redo the import. I do want to mention though, I never was able to reproduce issues with the import for logger in general.

from typesense-js.

Wiirlak avatar Wiirlak commented on June 15, 2024

Hi, we are currently using the Typescript version of Typesense, and i found few errors:

  • The field geo_distance_meters is missing in the SearchResponseHit interface (example in the documentation)
  • The ImportResponseFail interface contains:
    • document: DocumentSchema;
    • but it should be document: DocumentSchema[];

Thanks for this TS version anyway, feel amazing to work with it ๐ŸŽ‰

from typesense-js.

akash-joshi avatar akash-joshi commented on June 15, 2024

I'll try to debug this one: #32 (comment)

from typesense-js.

leeran7 avatar leeran7 commented on June 15, 2024

Hey, I'm currently swapping over from Algolia, and something that would be a great nice to have would be to add Generics.
I do see the Issue has been opened already here #152

Current:
const searchResults = await this.collections(collectionName).documents().search(options)
searchResults return type: SearchResponse<{}>

For me to get the hits with the correct types, I need to do something like
searchResults.hits?.map((hit) => hit.document) as Type[]

Suggestion:
const searchResults = await this.collections(collectionName).documents().search<Type>(options)
return type: SearchResponse<Type>
typeof searchResults[0].document === Type

from typesense-js.

nandorojo avatar nandorojo commented on June 15, 2024

Even better would be the ability to run a script that codegens the types, similar to what Prismic does.

from typesense-js.

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.