CLI
Install
sh
npm add -D @grpc.ts/cli @grpc.ts/core
sh
pnpm add -D @grpc.ts/cli @grpc.ts/core
sh
yarn add -D @grpc.ts/cli @grpc.ts/core
Configure
ts
// grpc-cli.ts
import type { IConfigProps } from '@grpc.ts/cli';
const config: IConfigProps = {
paths: ['../proto/*.proto'],
external: ['google.protobuf'],
};
export default config;
Run Script
sh
npm run gen-grpc-typing
sh
pnpm gen-grpc-typing
sh
yarn gen-grpc-typing
Default output will be protobufTypings
. Change output
option to specify the folder you want to store the typing files.
Monorepo
In case you are working on a monorepo project and want to share generated typings to all mono projects. From version 1.2.0
, @grpc.ts/cli
provides a config for this purpose.
ts
// grpc-cli.ts
import type { IConfigProps } from '@grpc.ts/cli';
const config: IConfigProps = {
paths: ['../proto/*.proto'],
external: ['google.protobuf'],
monorepo: {
multiEntries: true,
packageName: '@data/grpc',
workspacePath: './packages',
},
};
export default config;
This will initialize package.json
and tsconfig.json
at the path ./packages/@data/grpc
. Also exports multi-entries using package exports
.
Install the package, import type and use.
sh
npm --workspace=my-workspace add -D @data/grpc
sh
pnpm --filter=my-workspace add -D @data/grpc
sh
yarn workspace my-workspace add -D @data/grpc
ts
import type {
IExampleService,
ISendMessageRequest,
} from '@data/grpc/example3.interface';