Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Typescript-我不能用jest、@types/jest和ts-jest编译项目_Javascript_Typescript_Jestjs_Tsconfig_Ts Jest - Fatal编程技术网

Javascript Typescript-我不能用jest、@types/jest和ts-jest编译项目

Javascript Typescript-我不能用jest、@types/jest和ts-jest编译项目,javascript,typescript,jestjs,tsconfig,ts-jest,Javascript,Typescript,Jestjs,Tsconfig,Ts Jest,我试图用玩笑来模仿我的axios请求。这是我的测试: // External imports import axios, { AxiosPromise } from 'axios' // Personal imports import { getProgramApplications } from '#stores' import { programItem } from '../fixtures/zanox' describe('Zanox sales', async function (

我试图用玩笑来模仿我的axios请求。这是我的测试:

// External imports
import axios, { AxiosPromise } from 'axios'

// Personal imports
import { getProgramApplications } from '#stores'
import { programItem } from '../fixtures/zanox'

describe('Zanox sales', async function () {
    describe('Get program applications', async function () {
        it('should get program applications', async function () {
            const program = programItem()
            const mock = jest.spyOn(axios, 'get')
            mock.mockReturnValueOnce({ data: [program] } as unknown as AxiosPromise<unknown>)
            getProgramApplications(process.env.ZANOX_ADSPACE!)
        })
    })
})
最后,这是我的tsconfig.json:

问题是:当我试图编译我的项目时,终端说:

$ /home/olegario/hotsites/monorepo-hotsites/zanox/node_modules/.bin/tsc
node_modules/@types/mocha/index.d.ts:2680:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'beforeEach' must be of type 'Lifecycle', but here has type 'HookFunction'.

2680 declare var beforeEach: Mocha.HookFunction;
                 ~~~~~~~~~~

  node_modules/@types/jest/index.d.ts:32:13
    32 declare var beforeEach: jest.Lifecycle;
                   ~~~~~~~~~~
    'beforeEach' was also declared here.

node_modules/@types/mocha/index.d.ts:2698:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'afterEach' must be of type 'Lifecycle', but here has type 'HookFunction'.

2698 declare var afterEach: Mocha.HookFunction;
                 ~~~~~~~~~

  node_modules/@types/jest/index.d.ts:34:13
    34 declare var afterEach: jest.Lifecycle;
                   ~~~~~~~~~
    'afterEach' was also declared here.

node_modules/@types/mocha/index.d.ts:2714:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'describe' must be of type 'Describe', but here has type 'SuiteFunction'.

2714 declare var describe: Mocha.SuiteFunction;
                 ~~~~~~~~

  node_modules/@types/jest/index.d.ts:35:13
    35 declare var describe: jest.Describe;
                   ~~~~~~~~
    'describe' was also declared here.

node_modules/@types/mocha/index.d.ts:2735:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'xdescribe' must be of type 'Describe', but here has type 'PendingSuiteFunction'.

2735 declare var xdescribe: Mocha.PendingSuiteFunction;
                 ~~~~~~~~~

  node_modules/@types/jest/index.d.ts:37:13
    37 declare var xdescribe: jest.Describe;
                   ~~~~~~~~~
    'xdescribe' was also declared here.

node_modules/@types/mocha/index.d.ts:2749:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'it' must be of type 'It', but here has type 'TestFunction'.

2749 declare var it: Mocha.TestFunction;
                 ~~

  node_modules/@types/jest/index.d.ts:38:13
    38 declare var it: jest.It;
                   ~~
    'it' was also declared here.

node_modules/@types/mocha/index.d.ts:2763:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'test' must be of type 'It', but here has type 'TestFunction'.

2763 declare var test: Mocha.TestFunction;
                 ~~~~

  node_modules/@types/jest/index.d.ts:41:13
    41 declare var test: jest.It;
                   ~~~~
    'test' was also declared here.

node_modules/@types/mocha/index.d.ts:2770:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'xit' must be of type 'It', but here has type 'PendingTestFunction'.

2770 declare var xit: Mocha.PendingTestFunction;
                 ~~~

  node_modules/@types/jest/index.d.ts:40:13
    40 declare var xit: jest.It;
                   ~~~
    'xit' was also declared here.


Found 7 errors.

error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

我找到的关于它的大部分讨论都说要升级typescript版本,并从项目中删除jasmine。正如你所看到的,我的项目中没有茉莉花,而且我的typescript版本是最近的一个。为什么会发生这种情况?

一种解决方案是跳过外部项目的打字检查。在tsconfig.json中:


请参见此处的所有编译器选项:

一种解决方案是跳过外部项目的检查键入。在tsconfig.json中:

请参见此处的所有编译器选项:

{
    "compilerOptions": {
        "baseUrl": ".",
        "diagnostics": false,
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true,
        "module": "CommonJS",
        "moduleResolution": "node",
        "noErrorTruncation": true,
        "noFallthroughCasesInSwitch": true,
        "noImplicitReturns": false,
        "noUnusedLocals": true,
        "noUnusedParameters": false,
        "outDir": "./dist/",
        "resolveJsonModule": true,
        "sourceMap": true,
        "strict": true,
        "target": "es6",
        "lib": [
            "es5",
            "es6",
            "dom",
            "es2017"
        ],
        "paths": {
            "#database": [
                "src/setup/database"
            ],
            "#models/*": [
                "src/models/*"
            ],
            "#sales": [
                "src/sales/index"
            ],
            "#stores": [
                "src/stores/index"
            ],
            "#stores/*": [
                "src/stores/*"
            ],
            "#utils": [
                "src/utils/index"
            ],
            "#utils/*": [
                "src/utils/*"
            ],
            "#zanox/*": [
                "src/zanox/*"
            ],
            "*": [
                "node_modules/*",
                "src/_vendor/*"
            ]
        }
    },
    "include": [
        "src/**/*",
        "tests/**/*"
    ]
}
$ /home/olegario/hotsites/monorepo-hotsites/zanox/node_modules/.bin/tsc
node_modules/@types/mocha/index.d.ts:2680:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'beforeEach' must be of type 'Lifecycle', but here has type 'HookFunction'.

2680 declare var beforeEach: Mocha.HookFunction;
                 ~~~~~~~~~~

  node_modules/@types/jest/index.d.ts:32:13
    32 declare var beforeEach: jest.Lifecycle;
                   ~~~~~~~~~~
    'beforeEach' was also declared here.

node_modules/@types/mocha/index.d.ts:2698:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'afterEach' must be of type 'Lifecycle', but here has type 'HookFunction'.

2698 declare var afterEach: Mocha.HookFunction;
                 ~~~~~~~~~

  node_modules/@types/jest/index.d.ts:34:13
    34 declare var afterEach: jest.Lifecycle;
                   ~~~~~~~~~
    'afterEach' was also declared here.

node_modules/@types/mocha/index.d.ts:2714:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'describe' must be of type 'Describe', but here has type 'SuiteFunction'.

2714 declare var describe: Mocha.SuiteFunction;
                 ~~~~~~~~

  node_modules/@types/jest/index.d.ts:35:13
    35 declare var describe: jest.Describe;
                   ~~~~~~~~
    'describe' was also declared here.

node_modules/@types/mocha/index.d.ts:2735:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'xdescribe' must be of type 'Describe', but here has type 'PendingSuiteFunction'.

2735 declare var xdescribe: Mocha.PendingSuiteFunction;
                 ~~~~~~~~~

  node_modules/@types/jest/index.d.ts:37:13
    37 declare var xdescribe: jest.Describe;
                   ~~~~~~~~~
    'xdescribe' was also declared here.

node_modules/@types/mocha/index.d.ts:2749:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'it' must be of type 'It', but here has type 'TestFunction'.

2749 declare var it: Mocha.TestFunction;
                 ~~

  node_modules/@types/jest/index.d.ts:38:13
    38 declare var it: jest.It;
                   ~~
    'it' was also declared here.

node_modules/@types/mocha/index.d.ts:2763:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'test' must be of type 'It', but here has type 'TestFunction'.

2763 declare var test: Mocha.TestFunction;
                 ~~~~

  node_modules/@types/jest/index.d.ts:41:13
    41 declare var test: jest.It;
                   ~~~~
    'test' was also declared here.

node_modules/@types/mocha/index.d.ts:2770:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'xit' must be of type 'It', but here has type 'PendingTestFunction'.

2770 declare var xit: Mocha.PendingTestFunction;
                 ~~~

  node_modules/@types/jest/index.d.ts:40:13
    40 declare var xit: jest.It;
                   ~~~
    'xit' was also declared here.


Found 7 errors.

error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
{
    "compilerOptions": {
        ....
        "skipLibCheck": true
    }
}