Giter VIP home page Giter VIP logo

Comments (20)

suledisha avatar suledisha commented on June 5, 2024 6

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.

easyCZ avatar easyCZ commented on June 5, 2024 3

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.

jonnyreeves avatar jonnyreeves commented on June 5, 2024 1

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.

easyCZ avatar easyCZ commented on June 5, 2024 1

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.

jonny-improbable avatar jonny-improbable commented on June 5, 2024

@easyCZ I have a patch for this, will raise if/when #44 is approved and landed.

from ts-protoc-gen.

jonny-improbable avatar jonny-improbable commented on June 5, 2024

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.

stale avatar stale commented on June 5, 2024

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.

ramonberrutti avatar ramonberrutti commented on June 5, 2024

I'm with the same problem than @suledisha

from ts-protoc-gen.

easyCZ avatar easyCZ commented on June 5, 2024

@jonny-improbable do you still have your patch for removal of the name-spaces?

from ts-protoc-gen.

stale avatar stale commented on June 5, 2024

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.

fatfatson avatar fatfatson commented on June 5, 2024

have this version published?

from ts-protoc-gen.

fatfatson avatar fatfatson commented on June 5, 2024

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.

jonnyreeves avatar jonnyreeves commented on June 5, 2024

from ts-protoc-gen.

fatfatson avatar fatfatson commented on June 5, 2024
//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.

jonnyreeves avatar jonnyreeves commented on June 5, 2024

from ts-protoc-gen.

fatfatson avatar fatfatson commented on June 5, 2024

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.

jonnyreeves avatar jonnyreeves commented on June 5, 2024

from ts-protoc-gen.

stale avatar stale commented on June 5, 2024

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.

lozandier avatar lozandier commented on June 5, 2024

from ts-protoc-gen.

tmarkovski avatar tmarkovski commented on June 5, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.