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

TypeScript option verbatimModuleSyntax not supported #920

Closed
Zeswen opened this issue Sep 15, 2023 · 3 comments · Fixed by #921
Closed

TypeScript option verbatimModuleSyntax not supported #920

Zeswen opened this issue Sep 15, 2023 · 3 comments · Fixed by #921
Labels

Comments

@Zeswen
Copy link
Contributor

Zeswen commented Sep 15, 2023

TypeScript has an option verbatimModuleSyntax to always import types using the type prefix.

tsc fails to pass the checks.

import {
  CallOptions, // 'CallOptions' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.ts(1484)
  ChannelCredentials,
  Client,
  ClientOptions, // 'ClientOptions' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.ts(1484)
  ClientUnaryCall // 'ClientUnaryCall ' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.ts(1484)
  handleUnaryCall, // 'handleUnaryCall' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.ts(1484)
  makeGenericClientConstructor,
  Metadata,
  ServiceError, // 'ServiceError' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.ts(1484)
  UntypedServiceImplementation, // 'UntypedServiceImplementation' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.ts(1484)
} from "@grpc/grpc-js";

Including the type prefix to the previous variables will fix the issue.

@stephenh
Copy link
Owner

Hi @Zeswen , the codegen library that we use, ts-poet, has support for type imports by just adding a t: prefix, so changing like imp("CallOptions@@grpc/grpc-js") to imp("t:CallOptions@@grpc/grpc-js").

(The double @@ are weird, but the ts-poet import syntax came from awhile ago, before using @ as an org prefix was popular 🤷 )

But, anyway, this should be a pretty easy fix; if you'd like to work on a PR that just adds t: to the various imps you want changed, that'd be great. Thanks!

@Zeswen
Copy link
Contributor Author

Zeswen commented Sep 18, 2023

Thanks @stephenh for the insightful explanation! I've created #921 to address this 🙂

Amazing work on both ts-poet and ts-proto ❤️

@stephenh
Copy link
Owner

🎉 This issue has been resolved in version 1.157.1 🎉

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 a pull request may close this issue.

2 participants