Closed samhh closed 1 year ago
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
.
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?
Hey @pasinJ, thanks for the guidance! Planned for 0.16.1 0.17.0: https://github.com/samhh/fp-ts-std/commit/d393ae0e579382fe8ab2e3c34a7f8c712a702eeb
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 https://github.com/gcanti/fp-ts/issues/1726 (via #155) this might need to be reverted. Test it more before releasing.
Released in 0.17.0, looks good on my end.
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.