findify-js icon indicating copy to clipboard operation
findify-js copied to clipboard

@findify/sdk: Typescript types largely unusable due to enum usage

Open simonlovesyou opened this issue 3 years ago • 2 comments

When using @findify/sdk (version 2.2.3) it is not possible to use the included typescript types since most "Request" definitions depend on enums which are not exported in the distributed code.

import type { Search } from '@findify/sdk/types/request'
import { init } from '@findify/sdk'

const client = init({ /* configuration */ })

const search = (query: Search.Params['q']) => {
  const request: Search.Request = {
    type: 'search', // Type '"search"' is not assignable to type 'Type.Search'.ts(2322)
    params: {
      q: query
    }
  }
  return client.send(request)
}

We cannot import Type and use as replacement for the search string since it's an enum. We need to either able to import a js file with a separate type declaration for the enum OR type is specified with a const string instead for the different requests

simonlovesyou avatar May 02 '22 13:05 simonlovesyou

@simonlovesyou Hey, thanks for discovering this! We've released new SDK version: @findify/[email protected] where you'll be able to import RequestType:

import { RequestType } from '@findify/sdk';

Can you pls check how it works for you?

timaramazanov avatar May 24 '22 14:05 timaramazanov

Thanks for the fix @timaramazanov ! I can see in my editor that typescript is satisfied, the added docs looks great too! Unfortunately I can't run our application and test it because we're blocked from upgrading by #796 :/

simonlovesyou avatar Jun 28 '22 07:06 simonlovesyou