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

fix typescript config for rollup #3519

Merged
merged 2 commits into from
Aug 22, 2019

Conversation

cellog
Copy link
Contributor

@cellog cellog commented Aug 19, 2019

It turns out that even with the nodeResolve fixes, we still need the typescript plugin to build with rollup. This PR fixes that

@nickserv
Copy link
Contributor

Is this needed to fix the Babel type issue you mentioned? If so, I think we should go with your original approach and remove both nodeResolve and Babel (or at least the Babel Typescript preset). Otherwise we're going to have two tools compiling TypeScript syntax, which doesn't feel right to me.

@cellog
Copy link
Contributor Author

cellog commented Aug 19, 2019

We need babel for sure. It just removes all typescript syntax and converts to Javascript. We use tsc independently to verify types in the build step. I suppose there must be some other way to do this that is better?

To answer your question directly, when I ran the branch I'm about to draft PR, it failed on the first TS syntax. Maybe you can grab that branch and play around with it to find the best config? You seem more versed in the options than I am, it would be good to get this just right.

@cellog
Copy link
Contributor Author

cellog commented Aug 19, 2019

(#3520 is the draft PR @nickmccurdy)

@nickserv
Copy link
Contributor

The TypeScript compiler (tsc) can generate JS, it's not just a typechecker. If we disable noEmit, the TypeScript compiler will emit JS, and we can either remove Babel or just remove the TypeScript Babel preset if we need to use JS features not supported in TS (unlikely, even JSX works in TS).

Thanks, I'll take a look at #3520 and let you know if I have better ideas. Sorry if my previous config PRs caused confusion, I'm less experienced with the Babel TypeScript preset so I'm not as aware of its limitations compared to the TypeScript compiler.

@nickserv
Copy link
Contributor

I see what you mean, removing the TypeScript Rollup plugin causes unexpected token errors, but I'm not sure why (note that you have to disable JSX in tsconfig to this this first, or TS will think that the <> type assertion syntax is JSX). Meanwhile giving the extension list to Babel causes a circular dependency for some reason.

@nickserv
Copy link
Contributor

I managed to fix the syntax error, but there's a circular dependency in #3520. If you want to use the TypeScript compiler, you cannot import the declaration file from src/index.ts, because it has the same path, which will cause the index file to import itself and crash with a stack overflow. It seems like the best way to fix this would be to move index.d.ts to src/types.ts and import that in src/index.ts without importing src/index.ts, ., or .. in src/types.ts.

@nickserv
Copy link
Contributor

Also I'm still confused about how the Babel issue was solved. Is the TypeScript compiler needed for this or can we remove it in favor of Babel?

.gitignore Outdated Show resolved Hide resolved
@cellog
Copy link
Contributor Author

cellog commented Aug 20, 2019

ok, @nickmccurdy @timdorr I'm pretty sure this is the simplest working setup.

I tried changing whether babel had its extensions, and removing the nodeResolve. This fixed nothing. We need rollup-plugin-typescript2.

I think this is the best setup for now. Perhaps we'll find something better later

@nickserv
Copy link
Contributor

Thanks for your help, I know this isn't easy. In the case that we need TypeScript, I'd rather remove Babel, as we don't seem to be using any part of it that TypeScript itself can't handle. Would you like me to make a PR trying that? We could merge this for now, assuming it works with your other PR.

@cellog
Copy link
Contributor Author

cellog commented Aug 21, 2019

not at all, I enjoy this stuff :)

I prefer to keep both, as babel has much better support for transpiling features down. typescript is compiling to the latest javascript, and then babel refines it for us. I also imagine that in the future, support for ts will improve, and we can revisit it then.

The final call is @timdorr in this, my opinions are only opinions

@cellog
Copy link
Contributor Author

cellog commented Aug 21, 2019

OK. I finally have some clarity on this.

The configuration will go through 2 stages.

  1. While we still have an index.d.ts, the config in this PR will be used.
  2. Once all the types are moved out, we can use a config that is more standard, and remove the typescript plugin.

So, this PR should be considered a step-along-the-path PR, but an essential one.

@nickserv
Copy link
Contributor

nickserv commented Aug 21, 2019

Interesting, so our dependency on the TypeScript compiler is only because of how we're migrating the index.d.ts file? In that case I'm ok with merging this, but I'd prefer to switch to either only Babel or only TypeScript once it's fully migrated.

@cellog
Copy link
Contributor Author

cellog commented Aug 21, 2019

Interesting, so our dependency on the TypeScript compiler is only because of how we're migrating the index.d.ts file? In that case I'm ok with merging this, but I'd prefer to switch to either only Babel or only TypeScript once it's fully migrated.

This is explicitly the plan I'd like to take.

My motivation is having human-readable diffs along the way, and a working config as we go. If this seems too git-focused, I'm OK doing everything-at-once, but it should make it easier to roll back if I/we make a mistake along the way. At least that's my theory :P

@cellog
Copy link
Contributor Author

cellog commented Aug 22, 2019

so... anything need changing in this PR?

@timdorr
Copy link
Member

timdorr commented Aug 22, 2019

Sorry, I've been watching from a distance. Also, I've had family in town, so I haven't had time for OSS stuff in the evenings.

Let's get this in for now and then get it right back out :)

@timdorr timdorr merged commit a68f48e into reduxjs:ts-conversion Aug 22, 2019
@cellog
Copy link
Contributor Author

cellog commented Aug 23, 2019

no worries, thanks for taking a look!

@cellog cellog deleted the cellog-3500-config branch August 23, 2019 01:34
webMasterMrBin pushed a commit to webMasterMrBin/redux that referenced this pull request Aug 21, 2021
* fix typescript config for rollup

* h/t @timdorr remove need for .rpt2_cache ignore


Former-commit-id: 810580f
Former-commit-id: 1164735
webMasterMrBin pushed a commit to webMasterMrBin/redux that referenced this pull request Aug 21, 2021
* fix typescript config for rollup

* h/t @timdorr remove need for .rpt2_cache ignore


Former-commit-id: 810580f
Former-commit-id: 1164735
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.

3 participants