I made a simple example to test package.exports.types field and the settings read as follow
"exports": {
".": {
"import": "./build/index.js",
"require": "./build/index.js",
"default": "./build/index.js",
"types": "./build/index.d.ts"
},
"./foo": {
"import": "./build/foo.js",
"require": "./build/foo.js",
"default": "./build/foo.js",
"types": "./build/foo.d.ts"
},
"./package.json": "./package.json"
},
However, when I import this package in the another project, it says
error TS2307: Cannot find module 'exports-test/foo' or its corresponding type declarations.
1 import * as a from 'exports-test/foo'
And it seems that the typescript compiler can't find the type definition file for foo.
My typescript version is 4.6.3. And I think I followed every instruction stated in the official document.
What is wrong with my settings? It'd be very helpful if you can share the repository of a working example.