+
Skip to content

Unable to use mocker-api in commonjs with type-checking enabled #125

@ikatyang

Description

@ikatyang

Version: 2.3.0

Steps to reproduce:

  • execution passed, but type-checking failed

    mkdir mocker-api-repro-execution-passed-but-type-checking-failed
    cd mocker-api-repro-execution-passed-but-type-checking-failed
    npm init -y
    npm install typescript mocker-api
    echo '{"compilerOptions":{"allowJs":true,"checkJs":true,"allowSyntheticDefaultImports":true}}' > tsconfig.json
    echo 'const mockerApi = require("mocker-api"); mockerApi(null, null); console.log("execution passed")' > index.js
    npx tsc --noEmit
    node index.js
    index.js:1:42 - error TS2349: This expression is not callable.
        Type 'typeof import("~/mocker-api-repro-execution-passed-but-type-checking-failed/node_modules/mocker-api/lib/index")' has no call signatures.
    
        1 const mockerApi = require("mocker-api"); mockerApi(null, null); console.log("execution passed")
                                                   ~~~~~~~~~
    
    Found 1 error.
    
    execution passed
  • type-checking passed, but execution failed

    mkdir mocker-api-repro-type-checking-passed-but-execution-failed
    cd mocker-api-repro-type-checking-passed-but-execution-failed
    npm init -y
    npm install typescript mocker-api
    echo '{"compilerOptions":{"allowJs":true,"checkJs":true,"allowSyntheticDefaultImports":true}}' > tsconfig.json
    echo 'const mockerApi = require("mocker-api").default; mockerApi(null, null); console.log("execution passed")' > index.js
    npx tsc --noEmit
    node index.js
    ~/mocker-api-repro-type-checking-passed-but-execution-failed/index.js:1
    const mockerApi = require("mocker-api").default; mockerApi(null, null); console.log("execution passed")
                                                     ^
    
    TypeError: mockerApi is not a function
        at Object.<anonymous> (~/mocker-api-repro-type-checking-passed-but-execution-failed/index.js:1:50)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载