Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUNNING attempts at getting TS version selection working #1013

Merged
merged 13 commits into from
Apr 24, 2021

Conversation

markerikson
Copy link
Collaborator

@markerikson markerikson commented Apr 23, 2021

VERY WORKING MUCH QUERY SUCH VERSIONING

This is a completely failing attempt to get TS4.0 compat working, by creating a clone of query/react/index.d.ts named indexTs40.d.ts, swapping an import, and getting TS typesVersions detection working.

This is really built off of #1012 , so it's got all the changes there in terms of test updates, plus some reworking of the src/query/react/ files that probably shoulda been over here.

I've been using --traceResolution, and I can see TSC finding the typesVersion field in dist/query/react/package.json... and then it just seems to ignore it. If I have a types field in there, it settles on that no matter what the version check is. If I don't have a types field, it ends up latching on to main and deriving an index.d.ts from that.

Frankly I have no idea what the path mappings in typesVersions are supposed to be. Individual filenames? Paths relative to repo root? Paths relative to this folder? Noooo idea.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 23, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit d2aaff0:

Sandbox Source
Vanilla Configuration
Vanilla Typescript Configuration
rsk-github-issues-example Configuration

@github-actions
Copy link

github-actions bot commented Apr 23, 2021

Size Change: -2 B (0%)

Total Size: 84.4 kB

Filename Size Change
dist/redux-toolkit.cjs.development.js 11.8 kB -2 B (0%)
ℹ️ View Unchanged
Filename Size Change
dist/index.js 146 B 0 B
dist/redux-toolkit.cjs.production.min.js 5.78 kB 0 B
dist/redux-toolkit.esm.js 11.4 kB 0 B
dist/redux-toolkit.modern.development.js 9.22 kB 0 B
dist/redux-toolkit.modern.js 9.26 kB 0 B
dist/redux-toolkit.modern.production.min.js 4.33 kB 0 B
dist/redux-toolkit.umd.js 21.8 kB 0 B
dist/redux-toolkit.umd.min.js 10.7 kB 0 B

compressed-size-action

@markerikson
Copy link
Collaborator Author

markerikson commented Apr 23, 2021

Per Orta at https://twitter.com/orta/status/1385610364323237889 :

Checked the compiler, you’re failing this containsPath check: https://github.com/microsoft/TypeScript/blob/master/src/compiler/moduleNameResolver.ts#L1386

Because your resolved path doesn’t live inside the tree structure provided by the module, could be a security check

If it’s all internal, maybe move the matched dts into the package

So, will have to figure out a way around that.

Per @phryneas at https://twitter.com/phry/status/1385618747810095111 :

It is not necessary, but we will need "proxy directories", meaning directories with a package.json where the virtual entry point would be.
This is a pretty common hack, see jaredpalmer/tsdx#367 (comment)

Base automatically changed from feature/rtk-query-tests to feature/v1.6-integration April 24, 2021 01:22
@markerikson markerikson marked this pull request as ready for review April 24, 2021 04:13
@markerikson
Copy link
Collaborator Author

markerikson commented Apr 24, 2021

After several more hours of hacking, this appears to be working!

Lenz suggested that what we really needed was a ./src/query/react/versionedTypes folder with its own package.json, and the two TS40/41 types files in there:

image

I reworked the packaging and build setup to have that.

I've been using a standalone copy of the RTKQ React example app as my testbed. Ran into some more issues with TSC not handling typesVersions correctly, but some use of --traceResolutions gave me the debug info I needed to finally get this all sorted out.

I've seen TS 4.0 correctly parse typesVersions for the versionedTypes import (and then generate 2.4MB of types errors because it didn't recognize the hooks the source was still exporting). After redoing the service files to "manually" export the hooks under their correct names, TSC 4.0 correctly compiled the app, and I was then able to actually build it successfully with CRA.

The resulting bundle looks like this:

image

That looks basically as I'd expect it: both RTK and RTKQ in the bundle, ESM format, seemingly valid sizes.

I did have to revert the earlier ApiModule restructuring that I did. I hadn't run the tests in a while, and suddenly TS was screaming loudly because something had broken. All that is now in query/react/index.ts.

I also bumped ESBuild to latest just because. This actually caused problems because it now replaces process.env.NODE_ENV by default, so I had to switch it to platform: 'neutral'. But, that caused imports to not resolve right somehow. Manually passing the 'fields' and 'conditions' listed in the ESBuild docs for platform: 'browser' got those working again.

I think this basically wraps up the actual code integration aspect, and we can now work on integrating the docs.

@markerikson markerikson merged commit cce75bf into feature/v1.6-integration Apr 24, 2021
@markerikson markerikson deleted the feature/rtkq-ts40-compat branch April 24, 2021 04:25
@markerikson markerikson changed the title Failing attempts at getting TS version selection working RUNNING attempts at getting TS version selection working Apr 24, 2021
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