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

Support Typescript 4 #926

Open
vberlier opened this issue Nov 5, 2020 · 14 comments
Open

Support Typescript 4 #926

vberlier opened this issue Nov 5, 2020 · 14 comments
Labels
scope: dependencies Pull requests that update a dependency file solution: workaround available There is a workaround available for this issue

Comments

@vberlier
Copy link

vberlier commented Nov 5, 2020

Current Behavior

Creating a new project with the example code from the official release notes doesn't work:

type Arr = readonly any[];

export function concat<T extends Arr, U extends Arr>(arr1: T, arr2: U): [...T, ...U] {
  return [...arr1, ...arr2];
}
$ yarn build
semantic error TS1256: A rest element must be last in a tuple type.
$ yarn lint
Parsing error: Cannot read property 'map' of undefined

Workaround

For the moment I managed to work around it by updating typescript and typescript-eslint and forcing the resolutions:

$ yarn add --dev typescript@latest @typescript-eslint/eslint-plugin@latest @typescript-eslint/parser@latest
// package.json

"resolutions": {
  "**/typescript": "^4.0.5",
  "**/@typescript-eslint/eslint-plugin": "^4.6.1",
  "**/@typescript-eslint/parser": "^4.6.1"
}
@agilgur5 agilgur5 added the solution: workaround available There is a workaround available for this issue label Nov 5, 2020
@agilgur5
Copy link
Collaborator

agilgur5 commented Nov 7, 2020

Hmm.. So the linting portion duplicates #810 which just recently got unblocked by a new release of eslint-config-react-app upstream.

But oddly enough #810 doesn't report issues with any TS syntax. Perhaps there's a subset that's compatible but some of it isn't, per the TS release notes.

TSDX normally uses whatever version of TS is available in node_modules, which has allowed users to use newer versions of TS before TSDX upgraded to them. But I think since all versions were TS v3 previously, it would just get deduplicated / flattened in node_modules as a single TS version.
Since TS v4 released as a major (notably, TS doesn't follow SemVer as each minor has breaking changes in it too), I'm guessing this made two versions of TS appear in the node_modules tree and so TSDX ended up using the v3 which matches its internal version.
I actually wasn't sure exactly how this behavior would play out, so thanks for showing an example.

To respond to the request though, a breaking upgrade to TS v4, ESLint v7, Prettier v2, etc etc (one dep upgrade requires another dep upgrade requires another etc 😕 ) is already scheduled for v0.16.0. Because this dep upgade it's so breaking, I've planned it to occur when there are no other breaking changes occurring for the least possible confusion and to space out planned/required breakage.

Also thanks for providing the workaround with resolutions and confirming that it works.

@JustFly1984

This comment has been minimized.

@agilgur5
Copy link
Collaborator

@JustFly1984 please read the comments. This is already scheduled for v0.16.0, is very breaking and requires updates of several deps (one of which only recently updated), and has workarounds available...

I'm not sure what you mean by you can't build a new version... this is not a blocker as it has a workaround, and current TSDX can build.

samijaber added a commit to unsplash/unsplash-js that referenced this issue Nov 24, 2020
@viniciusflv
Copy link

In addition to the TS4 support, i'd like to say that the new TS4.1 template string types are not working properly. I'm not capable of saing the extension of the problem, but it would be really cool if you could also target this issue.
I Love this lib S2!

@agilgur5
Copy link
Collaborator

agilgur5 commented Dec 1, 2020

@viniciusflv if the resolutions workaround above doesn't work for you for template strings, then that would likely be a bug upstream in rollup-plugin-typescript2. But the workaround should work.
Template string types are a new syntax/feature so they're not backward compatible with older TS versions. But yes, I'm planning to upgrade to whatever the newest and fully ecosystem supported (e.g. eslint and prettier need to support new ASTs and rules with new versions, so it's not immediate) TS version is when v0.16.0 is released. Also you'll be able to bring your own version of TS 4.x once TSDX upgrades to it as one could with 3.x per my initial comment

devrnt added a commit to devrnt/react-use-intercom that referenced this issue Dec 3, 2020
Workaround will be removed in upcoming tsdx version: jaredpalmer/tsdx#926
@utkarshkukreti
Copy link

For anyone interested, here's the updated resolutions workaround I'm using for latest typescript and jest.

I'm using it in a new project and everything seems to be working fine; I'll update if anything breaks.

  "resolutions": {
    "**/@typescript-eslint/eslint-plugin": "^4.11.1",
    "**/@typescript-eslint/parser": "^4.11.1",
    "**/jest": "^26.6.3",
    "**/ts-jest": "^26.4.4",
    "**/typescript": "^4.1.3"
  }

miridius added a commit to miridius/serverless-telegram that referenced this issue Jan 1, 2021
See jaredpalmer/tsdx#926

Note that this solution is only possible with yarn
@agilgur5 agilgur5 added the scope: dependencies Pull requests that update a dependency file label Jan 10, 2021
Skn0tt added a commit to flightcontrolhq/superjson that referenced this issue Jan 27, 2021
Resolutions needed b/c of jaredpalmer/tsdx#926
Skn0tt added a commit to flightcontrolhq/superjson that referenced this issue Jan 27, 2021
* Update TSDX deps

* Update TypeScript

Resolutions needed b/c of jaredpalmer/tsdx#926

* Update Husky

* Update MongoDB
hassankhan added a commit to radicalcondor/singer-node that referenced this issue Feb 18, 2021
lukesmurray added a commit to lukesmurray/slate-extensions that referenced this issue Feb 26, 2021
stephenh added a commit to homebound-team/beam that referenced this issue Mar 9, 2021
@stephenh
Copy link

stephenh commented Mar 9, 2021

We're prototyping a new project on tsdx and after an ~hour of fighting "why does jsxImportSource" not work (for emotion setup), it turns out tsdx was using its own shadowed version of TypeScript. Pretty frustrating. Personally I'm close to moving off tsdx, but for now we can switch from npm to yarn and use the ^ resolutions.

All of the projects in our company are on TS 4.x and prettier 2.x, so kinda surprised to see tsdx behind on these.

Granted, it's open source / it's free / etc. :-), so I'm looking forward to liking/using tsdx going forward, but just reporting back today's frustrations from the field.

stephenh added a commit to homebound-team/beam that referenced this issue Mar 10, 2021
* Setup chromatic.

* Use babel-preset-css-prop instead of per-file pragmas.

* Get jsxImportSource working, move to yarn to get TS 4.x

See:

jaredpalmer/tsdx#926

* More yarn.

* Fix node version.

* Use exit once uploaded.

* Pass auto-accept-changes on main.

* Use a local jest.config.js so that Webstorm works.

* Use local semantic-release.

* Update comment.

* Remove babel-plugin b/c the preset adds it for us.
@TheBit
Copy link

TheBit commented Mar 10, 2021

@stephenh I also looked to this lib, but it has phantom dependencies all over the place and thus is incompatible out-of-the-box with Rush with pnpm. I tried to fix this myself, but when it took more then several days with no luck - I quit.

@yaquawa

This comment has been minimized.

kherge added a commit to kherge/js.result that referenced this issue Jun 30, 2021
TSDX does not appear to be maintained on this front: jaredpalmer/tsdx#926
@rhyek
Copy link

rhyek commented Jul 18, 2021

In case anyone is using pnpm >= 5.10.1 you can use overrides (https://pnpm.io/package_json#pnpmoverrides):

  "pnpm": {
    "overrides": {
      "typescript": "^4.3.0"
    }
  }

@aladdin-add
Copy link

just released a fork @weiran.zsd/tsdx, the main changes are:

  • drop node.js <12
  • upgrade eslint v7
  • upgrade typescript v4
  • upgrade jest v27

@doasync
Copy link

doasync commented Nov 15, 2021

I have used resolutions workaround #926 (comment) with updated versions and it worked too:

  "resolutions": {
    "**/@typescript-eslint/eslint-plugin": "^5.4.0",
    "**/@typescript-eslint/parser": "^5.4.0",
    "**/jest": "^27.3.1",
    "**/ts-jest": "^27.0.7",
    "**/typescript": "^4.4.4"
  }

@Ricardo-Marques
Copy link

The resolutions suggestions above did not fix my issue, which was a build error being thrown by babel anywhere that I attempted to leverage typescript template literals.

What ended up fixing that issue was upgrading @babel/core

yarn add --dev @babel/core@latest @typescript-eslint/eslint-plugin@latest @typescript-eslint/parser@latest

  "resolutions": {
    "**/typescript": "^4.6.2",
    "**/@typescript-eslint/eslint-plugin": "^5.16.0",
    "**/@typescript-eslint/parser": "^5.16.0",
    "**/@babel/core": "^7.12.3"
  }

@0xalecks
Copy link

To add on the previous comments, yarn 3 does not support glob patterns in resolutions (**/). This fixed the issue for me:

"resolutions": {
    "typescript": "4.8.4"
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: dependencies Pull requests that update a dependency file solution: workaround available There is a workaround available for this issue
Projects
None yet
Development

No branches or pull requests