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

fix: tsconfig conflict issue that occurs with ts-proto-descriptors #312

Merged
merged 1 commit into from
Jun 13, 2021

Conversation

protango
Copy link
Contributor

@protango protango commented Jun 7, 2021

When importing ts-proto-descriptors into a typescript project, it will try to import the typescript source code, and not the generated javascript. This is an issue when the dependent project's tsconfig file does not agree with the tsconfig for ts-proto.

For example, my project depends on ts-proto-descriptors has a tsconfig that has enabled esModuleInterop. But the ts-proto tsconfig does not have this option set, meaning the ts-proto-descriptors source is not compatible with my project and throws the following typescript errors:

node_modules/ts-proto-descriptors/google/protobuf/compiler/plugin.ts:609:5 - error TS2367: This condition will always return 'true' since the types 'Constructor<Long>' and '{ default: LongConstructor; prototype: Long; MAX_UNSIGNED_VALUE: Long; MAX_VALUE: Long; MIN_VALUE: Long; NEG_ONE: Long; ONE: Long; ... 11 more ...; fromValue(val: string | ... 2 more ... | { ...; }): Long; }' have no overlap.

609 if (util.Long !== Long) {
        ~~~~~~~~~~~~~~~~~~

node_modules/ts-proto-descriptors/google/protobuf/descriptor.ts:4526:5 - error TS2367: This condition will always return 'true' since the types 'Constructor<Long>' and '{ default: LongConstructor; prototype: Long; MAX_UNSIGNED_VALUE: Long; MAX_VALUE: Long; MIN_VALUE: Long; NEG_ONE: Long; ONE: Long; ... 11 more ...; fromValue(val: string | ... 2 more ... | { ...; }): Long; }' have no overlap.

4526 if (util.Long !== Long) {
         ~~~~~~~~~~~~~~~~~~


Found 2 errors.

This PR addresses the underlying issue by exporting only the generated javascript from ts-proto-descriptors (along with ts definition files for type safety). This means that it cannot be broken by the outer project's ts-config because it is already compiled.

From a developer perspective, there will be no change as the definition files will maintain type-safety, as if you were working with typescript directly. However if you really wanted to import the TS source, then you could also do that by just specifying the path explicitly (eg. import { FileDescriptorProto } from "ts-proto-descriptors/index").

NOTE: This change will require a release to NPM for https://www.npmjs.com/package/ts-proto-descriptors

@protango protango changed the title Fix tsconfig conflict issue that occurs with ts-proto-descriptors fix: tsconfig conflict issue that occurs with ts-proto-descriptors Jun 7, 2021
@protango
Copy link
Contributor Author

protango commented Jun 7, 2021

Also just realised this PR should resolve #217

@stephenh
Copy link
Owner

@protango thanks for the fix; I've pushed ts-proto-descriptors@1.3.0 up to npm, can you try it out and let me know if it works?

@stephenh
Copy link
Owner

🎉 This PR is included in version 1.81.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

2 participants