Skip to content

Conversation

buschtoens
Copy link

@buschtoens buschtoens commented Sep 24, 2020

By using typesVersions instead of types pointing to a single index declaration file, we enable consumers of react-query to also import directly from nested files, like react-query/core. These files are de-facto importable, but TypeScript does not "see" them currently.

I understand that in regular React day to day usage, this is irrelevant (or potentially even undesirable), but I am currently working on building a react-query clone for Ember.js and would love to use the rock-solid react-query/core as a foundation for this.

For react-query v3 I'd like to suggest splitting out the core lib into a standalone package to make code-sharing easier. It could still reside in this repo by switching to a yarn/lerna monorepo.

Thank you for considering! 😊

By using `typesVersions` instead of `types` pointing to a single `index` declaration file, we enable consumers of `react-query` to also import directly from nested files.
@vercel
Copy link

vercel bot commented Sep 24, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/tannerlinsley/react-query/2op9qrg0v
✅ Preview: https://react-query-git-fork-buschtoens-patch-1.tannerlinsley.vercel.app

@boschni
Copy link
Collaborator

boschni commented Sep 25, 2020

Tested this change in a project but it's seems to break the regular react-query import. The current package also does not have an entry point for react-query/core because the index file resides at react-query/lib/core or react-query/es/core. With this change TypeScript would think there is an entry point while there is none.

@buschtoens
Copy link
Author

buschtoens commented Sep 25, 2020

@boschni Thank you for looking into this, and sorry, that I broke it. 😓
I've restored the original types export, so that the standard pathless import from react-query works again. react-query/hydration also works, since the .d.ts file is located alongside the .js file in a standard location. I've also corrected the nested imports, so that react-query/es/* works correctly as well.

I've also verified that all these imports resolve correctly:

import { useInfiniteQuery, useQuery } from 'react-query';
import type { Query } from 'react-query/es/core';
import type { QueryCache } from 'react-query/es/core/queryCache';
import type { ReactQueryConfig } from 'react-query/es/core/types';
import type { HydrateProps } from 'react-query/hydration';

@boschni
Copy link
Collaborator

boschni commented Sep 25, 2020

No problem! I made some changes in the V3 branch to create multiple entry points: #1079. With these changes it should be possible to do the following, while supporting multiple export formats and types:

import { Query } from 'react-query/core'
import { useQuery } from 'react-query/react'
import { HydrateProps } from 'react-query/hydration'

@buschtoens buschtoens changed the title refactor(types): use typesVersions over types refactor(types): expose types for react-query/es/* Sep 25, 2020
buschtoens added a commit to ClarkSource/ember-query that referenced this pull request Sep 26, 2020
@buschtoens
Copy link
Author

Are you implying that you would rather hold back with this until v3 (#772) lands and close this PR or do you think that we could still ship this improvement for v2? 😊
I'd greatly appreciate that, but I can understand, if you would like to avoid the /es/ churn. If so, do you a rough ETA when the first pre-release versions will be released?

@boschni
Copy link
Collaborator

boschni commented Sep 29, 2020

Yes I would rather hold this one off in favor of the v3 release, I hope we can push out a pre-release this week

@buschtoens
Copy link
Author

Awesome! Looking forward to that. Thank you.

@buschtoens buschtoens closed this Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants