Is there a need for libraries to generate d.ts
files when they are already written in .ts
?
Typically, typescript libraries compile like this:
my-package/
- package.json
- lib/
- index.ts
- hello.ts
- dist/
- index.js
- index.d.ts
- hello.js
- hello.d.ts
// package.json
{
...
"main": "dist/index.js",
"types": "dist/"
}
What if we just use the ts file in the types
field instead?
my-package/
- package.json
- lib/
- index.ts
- hello.ts
- dist/
- index.js
- hello.js
// package.json
{
...
"main": "dist/index.js",
"types": "lib/index.ts"
}
Can the type of a ts file differ from a d.ts file? I'm interested in using a faster compiler like esbuild or swc for my library, but generating declarations is proving to be a bottleneck.