Closed catc closed 2 years ago
I believe @DavidTanner has stong(ish) opinions of pointing to the full .ts file. I'll let him help you =)
My personal preference is to use the *.ts
files for debugging. I found recently that errors were popping up because of strict: true
. Disabling that fixed the issue for me. I have gotten errors from the *.d.ts
files as well, so I'm not sure that either version is really safe.
The issue with the index.ts
file is that if it fails to compile on newer ts versions, you can't really fix those errors because it's in the package source code.
With index.d.ts
, you're just referencing the type declarations so ts won't actually try to compile the source code and fail; any errors will be in the consuming/parent code using the package, if this makes sense.
I've seen both. The *.d.ts
file can have issues, but I agree, it can by bypassed by telling typescript to ignore libraries.
However, I find it invaluable to debugging having the actual source available, especially when stepping through the code.
The error in the screenshot above is caused by the strict
value in the tsconfig.json
file being enabled. It does need to be fixed.
The TypeScript documentation says that the types field should point to the declaration file: https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#including-declarations-in-your-npm-package
Would it solve both our issues if we were to publish both, and point the types to the .d.ts
file?
I think so!
Currently
index.ts
is being used astypes
in package.json which is causing compiler errors when upgrading to newer versions of typescript (since it tries to compile the entire package instead of just referencing the types). I think this could be resolved by generating anindex.d.ts
and referencing that instead.