Registry / devops / typescript-grpc

typescript-grpc

JSON →
library0.0.2jsnpmunverified

A minimalistic annotation-based TypeScript library for building gRPC servers and clients. Current version 0.0.2. Releases are infrequent. Differentiators: uses TypeScript decorators to define services and messages, auto-generates .proto files from annotated classes, and supports modern async/await handlers. Requires manual proto loading via @grpc/proto-loader and grpc package. Less mature than alternatives like @grpc/grpc-js or ts-protoc-gen; limited to basic unary calls.

npm install typescript-grpc
INSTALL
IMPORT
SIG · TYPESCRIPT-GRPC
T
typescript-grpc
devopsjavascriptv0.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Service
import { Service } from 'typescript-grpc'
const Service = require('typescript-grpc').Service
ESM-only; named export for decorating service classes.
Method
import { Method } from 'typescript-grpc'
import Service from 'typescript-grpc'
Method is a named export, not a default export.
generateProto
import { generateProto } from 'typescript-grpc'
import { GenerateProto } from 'typescript-grpc'
CamelCase; generates a .proto file and returns the path.

Sets up a gRPC server using decorators for service and message definitions, auto-generates .proto, and starts listening on port 50051.

import { Type, Field, Message } from 'protobufjs'; import { Service, Method, generateProto, wrapServiceMethods } from 'typescript-grpc'; import { load } from '@grpc/proto-loader'; import { Server, ServerCredentials, ServiceDefinition } from 'grpc'; @Type.d() class HelloReply extends Message<HelloReply> { @Field.d(1, 'string') message: string; } @Type.d() class HelloRequest extends Message<HelloRequest> { @Field.d(1, 'string') name: string; } @Service() class Greeter { @Method({ requestType: 'HelloRequest', requestStream: false, responseType: 'HelloReply', responseStream: false, }) async sayHello(req: HelloRequest): Promise<HelloReply> { return new HelloReply({ message: `Hello ${req.name}` }); } } async function main() { const service = new Greeter(); const protoPath = await generateProto('greeter'); const packageDef = await load(protoPath, { keepCase: true }); const server = new Server(); server.addService(packageDef.Greeter as ServiceDefinition<any>, wrapServiceMethods(service)); server.bind('0.0.0.0:50051', ServerCredentials.createInsecure()); server.start(); console.log('Server started'); } main();
Debug
Known issues
gotchaPackage requires peer dependencies grpc, protobufjs, and @grpc/proto-loader; does not install them automatically.
fix
Run 'npm install grpc protobufjs @grpc/proto-loader' alongside typescript-grpc.
affects: >=0.0.0
deprecatedThe 'grpc' package is deprecated; '@grpc/grpc-js' is the recommended replacement.
fix
Migrate to '@grpc/grpc-js' and update imports accordingly.
affects: >=0.0.0
gotchaTypeScript decorators require 'experimentalDecorators' and 'emitDecoratorMetadata' to be enabled in tsconfig.json.
fix
Set 'experimentalDecorators': true and 'emitDecoratorMetadata': true in tsconfig.json.
affects: >=0.0.0
gotchagenerateProto() call must happen after service class definitions; it analyzes the class hierarchy at runtime.
fix
Ensure all service classes are imported/defined before calling generateProto.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'protobufjs'
Missing required peer dependency 'protobufjs'
fix
npm install protobufjs
TypeError: Class extends value undefined is not a constructor or null
Missing protobufjs import for Message class when using @Type.d decorator
fix
Add 'import { Message } from 'protobufjs'' before using @Type.d
SyntaxError: Unexpected token @
TypeScript decorators not enabled in tsconfig or using plain JavaScript
fix
Enable 'experimentalDecorators' and 'emitDecoratorMetadata' in tsconfig.json, or use TypeScript compiler.
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies
@grpc/proto-loaderrequiredRequired to load generated .proto files
grpcrequiredCore gRPC library for server/client
protobufjsrequiredRequired for Type decorators and Message base class
Agent activity
6 hits · last 30 days
node
6
Resources
typescript-grpc — npm install typescript-grpc · libregistry