npm package must not be shipped with TypeScript source code
See original GitHub issueIssue and Steps to Reproduce
npm package MUST NOT be shipped with TypeScript source code and instead ship a bundled JS file and TypeScript definition files instead (.d.ts
files)
This is important because importing the module from the package causes the TypeScript compiler to link against the source code inside the npm package, which is not desirable:
import { OidcProvider } from '@axa-fr/react-oidc';
Which causes the project to pick up errors from transitive dependency:
Notice that the TypeScript compile errors came from the @openid/appauth
project, not the react-oidc
code itself.
Versions
6.5.5
Screenshots
Provided above
Expected
Importing from react-oidc
project resolves to the TypeScript definition files (.d.ts
) not the .ts
source code themselves
Actual
Importing from react-oidc
project resolves to the .ts
source code of the project itself, which is not desirable
Additional Details
A library author might have a faulty import or might only provide typescript files for his library and not transpiled code.
libraries shouldn’t publish *.ts files,
https://github.com/microsoft/TypeScript/issues/40426
- Installed packages:
TypeScript 4.8.3
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Thank you again @ryanelian for your awesome feedback. I have revert to CommonJS and published a fixed version.
Also, something kind of related to producing JS output for the package…
If you do this, the package would be optimized for build systems (since almost everyone are writing React codes using Babel / Next.js / webpack / some kind of build tools) anyway.
ES2015 output will reduce the package size. Babel / etc. usually consume them to produce ES5 codes if needed anyway. You can even probably dial that up to ES2017 so that
async
codes are preserved (so that TypeScript won’t generate awaiter function on every files, saving more file size).ESNext module will ensure that bundlers such as webpack / etc. can perform tree-shaking optimization (removing codes that aren’t really used).
I recommend using these options instead of ES5 + CommonJS.