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

Incorrect export of core types #1290

Closed
Techn1x opened this issue Jun 29, 2023 · 2 comments · Fixed by #1301
Closed

Incorrect export of core types #1290

Techn1x opened this issue Jun 29, 2023 · 2 comments · Fixed by #1301
Labels
✨ enhancement New feature or request

Comments

@Techn1x
Copy link
Contributor

Techn1x commented Jun 29, 2023

The problem

When I run tsc --build I get this error

tests/helpers/snapshot.ts:2:38 - error TS7016: Could not find a declaration file for module '@percy/core'. '/MY_APP_PATH/node_modules/.pnpm/@[email protected]/node_modules/@percy/core/dist/index.js' implicitly has an 'any' type.
  There are types at '/MY_APP_PATH/node_modules/@percy/core/types/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@percy/core' library may need to update its package.json or typings.

2 import type { SnapshotOptions } from '@percy/core'

In other words, it knows types exist for this package, but due to how the package.json is setup it's not supposed to know 😛

I think this is due to typescript updating how it expects types to be exported (in particular a config update here tsconfig/bases#197 ) - it's to do with these lines

"types": "./types/index.d.ts",
"type": "module",
"exports": {
".": "./dist/index.js",
"./utils": "./dist/utils.js",
"./config": "./dist/config.js",
"./install": "./dist/install.js",
"./test/helpers": "./test/helpers/index.js",
"./test/helpers/server": "./test/helpers/server.js"

I believe the index types file should be listed under exports "." as well as the types entry in package.json (and the types entry should be kept as fallback for older TS versions)
This stack overflow post explains it pretty well https://stackoverflow.com/a/76212193


The same issue is probably present for a handful of other packages in this monorepo that also export types, but I'm only using core so that's all I've encountered.

Environment

  • Node version: 18.6.0
  • @percy/cli version: 1.26.1
@itsjwala itsjwala added the ✨ enhancement New feature or request label Jun 29, 2023
@itsjwala
Copy link
Contributor

hey @Techn1x thanks for reporting, we'd be happy to receive a PR.

@Techn1x
Copy link
Contributor Author

Techn1x commented Jul 6, 2023

Thanks @itsjwala I have opened that PR here #1301

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants