Not all typescript types can be imported #6147
Unanswered
Njitram2000
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
TL;DR:
How do you import (for example) the type
RangeConnectorParams
in local code which does not have theexport
keyword in the source?Details
Firstly, I have not been able to find any documentation or (extensive) code examples with typescript so if anyone knows where I can find that, it would be great.
I want to work with typescript so that I can know what types functions and objects require as input when calling them and so that I can specify in my own functions and class variables what types are returned.
Sometimes Instantsearch works by chaining 3 factory functions with generics in a row, resulting in VSCode just saying that the parameter for the final function is of type "any". I have found that manually constructing a type locally based on the standard types helps with this, as I will show with __RangeConnection in my example.
The InstantSearch types are present in the packages but it seems that more than half of them do not have the export keyword, meaning I can inspect on hover and ctrl+click but I cannot import them into my own files.
I found one or two github threads from a few years ago where this is pointed out and the algolia team said they would export them via the parent packages. This has resulted in the possiblity to import types from about 4 different paths but they all end up being the same type passed along. But that does not seem to solve the problem that a lot of the types are not exported. I use the VS code import suggest and it suggests nothing for those types. However, maybe I'm just doing it wrong.
Here is an example:
Note that
RangeConnectorParams
andRangeWidgetDescription
can be imported butRangeSliderWidgetParams
cannot which results in a red line in VS Code.It is present in
instantsearch.production.min.d.ts
but does not have the export keyword whileRangeConnectorParams
andRangeWidgetDescription
do.The workaround I have been doing is copying the whole non-exported types from the InstantSearch packages and recreating them locally to import those instead. It works but it'll become hard to maintain in the future when InstantSearch is updated and it's a lot of overhead.
So my question is: is it possible to import the types that do not have an export keyword? Is it a lack of knowledge on my side or a missing feature of IntstantSearch?
Beta Was this translation helpful? Give feedback.
All reactions