Comments (20)
I am experiencing the issue raise by @lozandier. I am unable to use the generated TypeScript proto file with Babel 7. The proto file contains namespaces that Babel 7 does not support. @jonny-improbable can you please suggest a work around for this issue. Thanks!
from ts-protoc-gen.
Taking a quick look, a possible replacement for the namespace problem could be to generate the following:
export class SimpleService {
static serviceName = "examplecom.SimpleService";
static readonly DoUnary = {
methodName: "DoUnary",
service: SimpleService,
requestStream: false,
responseStream: false,
requestType: examplecom_simple_service_pb.UnaryRequest,
responseType: othercom_external_child_message_pb.ExternalChildMessage,
}
static readonly DoStream = {
methodName: "DoStream",
service: SimpleService,
requestStream: false,
responseStream: true,
requestType: examplecom_simple_service_pb.StreamRequest,
responseType: othercom_external_child_message_pb.ExternalChildMessage,
}
}
It should be equivalent in functionality to the namespace version and would not break existing functionality.
from ts-protoc-gen.
Thanks for reporting @lozandier, we would be happy to consider a pull request for this feature assuming there is no regression to the public API and interoperability with grpc-web.
from ts-protoc-gen.
Hi @lozandier,
Thanks for the issue. This is interesting and could yield a simpler declaration. We will need to investigate further how the transition would work and if we could do it progressively without breaking the API.
A PR is welcome, should you wish to give it a go.
from ts-protoc-gen.
@easyCZ I have a patch for this, will raise if/when #44 is approved and landed.
from ts-protoc-gen.
Whoops. #45 only removed namespaces from Service Definitions (_pb_service.d.ts
), not from the Proto definitions (_pb.d.ts
). Thanks for raising this to my attention @easyCZ :)
from ts-protoc-gen.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from ts-protoc-gen.
I'm with the same problem than @suledisha
from ts-protoc-gen.
@jonny-improbable do you still have your patch for removal of the name-spaces?
from ts-protoc-gen.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from ts-protoc-gen.
have this version published?
from ts-protoc-gen.
Whoops. #45 only removed namespaces from Service Definitions (
_pb_service.d.ts
), not from the Proto definitions (_pb.d.ts
). Thanks for raising this to my attention @easyCZ :)
will it be fixed soon?
from ts-protoc-gen.
from ts-protoc-gen.
//replace=require("replace")
//find,exec are from "shelljs"
find(outputDir).forEach(p => {
if (p.endsWith('.ts') || p.endsWith('.js')) {
console.log(p);
exec(`gsed -i '1s/^/\\/\\* eslint-disable \\*\\/\\n/\' ${p}`);
}
if (p.endsWith('.ts')) {
replace({
paths: [p],
regex: /export namespace (.*) \{\n((.*\n)+?).*\}\n\}/gm,
replacement: (m, p1, p2) => `${p2}\n}`.replace('AsObject', `${p1}AsObject`)
});
replace({
paths: [p],
regex: /: (.+).AsObject/g,
replacement: (m, p1, p2) => `: ${p1}AsObject`
});
}
});
it's my workaround...
remove all namespace and add the name to their AsObject
type, also modify the function's return type.
from ts-protoc-gen.
from ts-protoc-gen.
that's not a fix in source, just a util script to fix the generated files ..
I think it will take much more time to learn into the source than just hacking the output -_-!
from ts-protoc-gen.
from ts-protoc-gen.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from ts-protoc-gen.
from ts-protoc-gen.
Would love to see this issue addressed. It is currently making it impossible to use it with React Native due to dependency on Babel 7.
from ts-protoc-gen.
Related Issues (20)
- d.ts files not generated HOT 4
- setXX() method return type is wrong in .d.ts file HOT 1
- proto3 - required / optional fields HOT 4
- Could we support friendlier object-literal syntax for service methods? HOT 1
- Fix TypeScript annotations for setters HOT 4
- Error: 13 INTERNAL: Request message serialization failure: Expected argument of type xxx HOT 3
- OnHeaders callback is not accessible. HOT 2
- How to deal with extensions? HOT 1
- Bad TS types for proto3 optional fields HOT 1
- Generate grpc-web code that use import than require HOT 5
- Error of protoc compiles FieldOption when using a enum from other proto
- Why is there no off() method on ResponseStream ?
- Does it support generating ES6 specification JS files and using them in grPC-Web
- protobuf v21 can't find protoc-gen-js HOT 3
- Module not found error while importing from _pb.d.ts file
- Getting the string name of Protobuf object
- Trailing underscore, toObject produces object that does not conform to AsObject
- The proper user code
- no set method TS types for proto3 Map field
- Typing for repeated extension fields generated incorrectly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ts-protoc-gen.