lifeomic / axios-fetch

A WebAPI Fetch implementation backed by an Axios client
MIT License
170 stars 30 forks source link

Update package.json types to reference index.d.ts #96

Closed catc closed 2 years ago

catc commented 2 years ago

Currently index.ts is being used as types 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 an index.d.ts and referencing that instead.

mdlavin commented 2 years ago

I believe @DavidTanner has stong(ish) opinions of pointing to the full .ts file. I'll let him help you =)

DavidTanner commented 2 years ago

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.

catc commented 2 years ago

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.

See source Screen Shot 2021-10-19 at 12 18 02 PM

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.

DavidTanner commented 2 years ago

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.

lencioni commented 2 years ago

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

DavidTanner commented 2 years ago

Would it solve both our issues if we were to publish both, and point the types to the .d.ts file?

lencioni commented 2 years ago

I think so!