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

#1526: Fixed missing import of the Cheerio type #1527

Merged
merged 1 commit into from May 16, 2020
Merged

Conversation

sk-pub
Copy link
Contributor

@sk-pub sk-pub commented May 4, 2020

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

Other information:

sk-pub pushed a commit to sk-pub/vue-server-test-utils that referenced this pull request May 4, 2020
@lmiller1990
Copy link
Member

Are you sure this is necessary? I am not seeing this typing error in dev in VSCode.

@sk-pub
Copy link
Contributor Author

sk-pub commented May 6, 2020

Are you sure this is necessary? I am not seeing this typing error in dev in VSCode.

Yes. I cannot compile my project, which depends on @vue/server-test-utils, because of this.

And VS Code shows the error:
image

@lmiller1990
Copy link
Member

I don't get this one.

image

I will ask someone with more TS knowledge, please wait a moment.

@sk-pub
Copy link
Contributor Author

sk-pub commented May 6, 2020

Probably, you have Cheerio registered globally somehow.

@pikax
Copy link
Member

pikax commented May 6, 2020

@unicrus works fine for me, can you run yarn --check-files?

If that doesn't work, can you check if you have the file node_modules/@types/cheerio/index.d.ts?

EDIT: If still doesn't work, please remove node_modules folder and do a fresh install.

@sk-pub
Copy link
Contributor Author

sk-pub commented May 8, 2020

@lmiller1990, @pikax please take a look at the example to reproduce the bug: https://github.com/unicrus/vue-server-test-utils-1526.

TypeScript is a strictly typed language, all types must be defined before usage.

@pikax
Copy link
Member

pikax commented May 8, 2020

@vue/server-test-utils has cheerio and @types/cheerio has dependencies.

Your repo is overriding the types in tsconfig.json

  "types": [
      "@types/node"
    ]

Making typescript only load those types! As per the documentation

If types is specified, only packages listed will be included

If you remove the types option, it will pick up the types by default. Or you can add Cheerio to your types

    "types": [
      "@types/node", 
      "@types/cheerio"
    ]

@sk-pub
Copy link
Contributor Author

sk-pub commented May 8, 2020

That's right. But @vue/test-utils does not rely on global types for everything else, like Vue or Vuex. They're explicitly imported. Why should Cheerio be different? It's not a well-known type.

@seyfer
Copy link

seyfer commented May 14, 2020

I cannot build my TS project because of this issue.

#571 (comment)

so I was forced to do this
yarn remove @vue/server-test-utils @types/cheerio cheerio

and rewrite my tests...

@lmiller1990
Copy link
Member

@pikax any down sides to merge this types PR? I don't know TS super well, seems like it's blocking a few people - I don't see any downsides to the extra import (right?)

package.json Outdated Show resolved Hide resolved
packages/server-test-utils/types/index.d.ts Outdated Show resolved Hide resolved
@pikax
Copy link
Member

pikax commented May 14, 2020

Sorry, got side tracked and this went under the radar.

My requested changes are not required, is just less code, if you want you can merge this.

The explanation is, cheerio types don't expose a default import, but when you import with typescript it expects to have the default export, the flag on the the script tells typescript to basically do import * as if no default module is available.

@lmiller1990
Copy link
Member

@unicrus if you can make those changes we can get this merged and released - we have a release in a day or two.

@sk-pub
Copy link
Contributor Author

sk-pub commented May 15, 2020

@lmiller1990, done. Thanks.

@lmiller1990 lmiller1990 merged commit 7e36d77 into vuejs:dev May 16, 2020
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.

None yet

4 participants