Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not publish ts sources to npm #440

Open
cronon opened this issue Jan 21, 2020 · 4 comments
Open

Do not publish ts sources to npm #440

cronon opened this issue Jan 21, 2020 · 4 comments

Comments

@cronon
Copy link

cronon commented Jan 21, 2020

In typescript project, it might not be possible to import incremental-dom@0.7.0 with import because in this case typescript will try to compile source files from node_modules. But the project may have different compiler options and typescript version and incremental-dom sources will fail to compile. Unfortunately, the only workaround I found is to use require()
https://github.com/Microsoft/TypeScript/wiki/FAQ#why-is-a-file-in-the-exclude-list-still-picked-up-by-the-compiler

In general, ts code should not be published to npm
microsoft/TypeScript#22228

@ScottAwesome
Copy link

ScottAwesome commented Feb 19, 2020

you can instead use an alias with your bundler to import from the relevant module.

https://webpack.js.org/configuration/resolve/
https://github.com/rollup/plugins/tree/master/packages/alias
https://parceljs.org/module_resolution.html
https://github.com/benbria/aliasify

Typescript also has a safety valve with path mapping:

https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping

I and a growing community of people really prefer the unmodified source being shipped, particularly if its typescript source code, so we can get all the completions properly (sometimes projects don't generate declarations properly). Also, it allows for more advanced use cases where the developer can compile the source code in an appropriate manner. It also gets around source code not compiled with newer versions of typescript (so they don't include the updated tslib helpers etc).

I think this is a much more nuanced discussion, and I think Microsoft should rethink this being the general advice and plan accordingly, in my not so humble opinion.

I do think you should ship both targeted source code and unmodified source code though.

There is a reason why the esnext key is common in package.json files :)

@sgammon
Copy link

sgammon commented Feb 19, 2020

agree with @ScottAwesome, we use the TS sources...

@justinfagnani
Copy link

It's a much better idea to publish and consume the .d.ts files if what you're after is the typings. You should not try to compile another project's TypeScript source with your project settings as they might not match. I'm getting compiler errors because of this that skipLibCheck is not fixing because I run with very strict options turned on.

@matthewp
Copy link

matthewp commented Jan 12, 2023

Same as above, using skipLibCheck doesn't solve issues because tsc only applies that option for d.ts files. This has required me to downgrade to 0.6.0 for now. Happy to submit a PR to change this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants