ts-detox-example
ts-detox-example copied to clipboard
Fix Detox typings to not clash with Jest's
Which version are you using? and could you post an example repo?
@types/detox
was updated to fix that issue in https://github.com/DefinitelyTyped/DefinitelyTyped/pull/32248
https://github.com/TheBlinkMan/detox-jest-typescript-error
Am i missing something?
I updated the dependencies in the master branch and still got the same result.
Thanks for providing a repo! I am seeing the error when I run the tsc
command:
bash-3.2$ yarn tsc index.ts --lib ES2015 --noEmit
yarn run v1.13.0
$ /.../detox-jest-typescript-error/node_modules/.bin/tsc index.ts --lib ES2015 --noEmit
node_modules/@types/detox/index.d.ts:11:11 - error TS2451: Cannot redeclare block-scoped variable 'expect'.
11 const expect: Detox.Expect<Detox.Expect<any>>;
~~~~~~
node_modules/@types/jest/index.d.ts:37:15
37 declare const expect: jest.Expect;
~~~~~~
'expect' was also declared here.
node_modules/@types/jest/index.d.ts:37:15 - error TS2451: Cannot redeclare block-scoped variable 'expect'.
37 declare const expect: jest.Expect;
~~~~~~
node_modules/@types/detox/index.d.ts:11:11
11 const expect: Detox.Expect<Detox.Expect<any>>;
~~~~~~
'expect' was also declared here.
Found 2 errors.
error Command failed with exit code 1.
This is an issue with the type definitions for Detox and Jest (they both declare expect
as a global constant), and not your code. You can disable type-checking the typings themselves using --skipLibCheck
That will skip type checking of all node_modules/@types libraries and node_modules d.ts declaration libraries. This is not the ideal solution. I think the only way is to use your detox + jest + typescript guide https://github.com/wix/Detox/pull/1001 and create a new package inside e2e folder.
I understand that and also don't appreciate having to do that; however I don't consider to be a major issue since it still checks if you're using the types from @types
correctly. The ideal solution would be to fix the Detox typings to not clash with Jest's, which I've not had time to do
@solkaz I may be seeing a similar issue whilst attempting to get this great example to run from CI.
Before I open a new issue though, which could be CI specific environment, I just wanted to know if you've tried this repo on any CI service such as appcenter.ms or circleci.com or travis-ci.org or bitrise.io yet?
I've not run this specific example on those specific services, no; but the project that I based this example on runs on GitlabCI.
Feel free to create an issue and we'll determine if it's a duplicate or not!
After the most recent fixes to type Detox typing, as noted on #3, tests are running without errors.
However, I agree that running yarn tsc
in this project will reveal errors.
So @solkaz, perhaps rename this issue to "Fix Detox typings to not clash with Jest's" and leave it open?
Changed title of issue from Still getting "Cannot redeclare block-scoped variable 'expect"' ERROR
to Fix Detox typings to not clash with Jest's
Just encountered this - my quick fix was to include the following at the top of each test file:
import {expect} from 'detox';
Not ideal - but it works.
Is there a real solution though? 🙂
I run the next coomand on CI to check TS for all code base
npx tsc --noEmit
and it fail after adding a @types/detox
module
node_modules@types/detox/index.d.ts
Error:(15, 11) TS2451: Cannot redeclare block-scoped variable 'expect'.
node_modules/@types/jest/index.d.ts
Error:(47, 15) TS2451: Cannot redeclare block-scoped variable 'expect'.
@retyui I have same problem! Anyone resolve it? Please, don't suggest --skipLibCheck
.
As much as pirroman is gonna hate me here, I've put skipLibcheck into my tsconfig and I have no regrets. It made a bunch of node_modules type errors get hidden. Hidden, not fixed, but, you know, hidden.
I create a copy of detox types and fix conflict locally