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

TypeScript exports support in 4.7 #117

Closed
samhh opened this issue Apr 9, 2022 · 3 comments
Closed

TypeScript exports support in 4.7 #117

samhh opened this issue Apr 9, 2022 · 3 comments
Milestone

Comments

@samhh
Copy link
Owner

samhh commented Apr 9, 2022

https://devblogs.microsoft.com/typescript/announcing-typescript-4-7-beta/#package-json-exports-imports-and-self-referencing

Could improve the manifest configuration, it's a bit hacky at the moment.

@pasinJ
Copy link

pasinJ commented Apr 12, 2023

I'm not sure if I should post it here or create a new issue.
In my Typescript project (typescript: 5.0.4, fp-ts-std: 0.16.0), I found that the following error showed up when I enabled the strict mode and set module to Node16 or NodeNext.

Reproduction repository

fp-ts-std-index
fp-ts-std-file

According to Typescript docs,

With TypeScript’s original Node support, it would look for a "main" field, and then look for declaration files that corresponded to that entry. For example, if "main" pointed to ./lib/index.js, TypeScript would look for a file called ./lib/index.d.ts. A package author could override this by specifying a separate field called "types" (e.g. "types": "./types/index.d.ts").

I think because fp-ts-std puts .d.ts and .js into separated folders, so it may cause Typescript to cannot find the type definitions. If I set the types as the document suggested, it can solve the error.

fp-ts-std/package.json
...
"exports": {
    ".": {
      "types": "./dist/types/index.d.ts",
      "require": "./dist/cjs/index.js",
      "import": "./dist/esm/index.js"
    },
    "./*": {
      "types": "./dist/types/*.d.ts",
      "require": "./dist/cjs/*.js",
      "import": "./dist/esm/*.js"
    }
  },
...

Could we consider applying this to improve the configuration?

@samhh
Copy link
Owner Author

samhh commented Apr 14, 2023

Hey @pasinJ, thanks for the guidance! Planned for 0.16.1 0.17.0: d393ae0

Confirmed that works in a dummy project with both new and old module resolutions (where 0.16.0 failed), and at least typechecks in a work project.

Note to self: As per gcanti/fp-ts#1726 (via #155) this might need to be reverted. Test it more before releasing.

@samhh
Copy link
Owner Author

samhh commented Jun 17, 2023

Released in 0.17.0, looks good on my end.

@samhh samhh closed this as completed Jun 17, 2023
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

No branches or pull requests

2 participants