Add a flag for proto-loader-gen-types to only output the restrictive type and remove the "__Output" from the name
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- 機能追加
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- node.js, typescript
調査の方向性
まず proto-loader-gen-types のエントリポイントと既存の生成オプションを特定し、次に permissive インターフェースと restrictive インターフェースが出力される箇所を追跡します。flag によって permissive インターフェースを抑制し、restrictive インターフェースにその名前を付けられ、生成された出力と関連する動作が検証されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Is your feature request related to a problem? Please describe.
We have several HTTP + gRPC services where we have the same shape objects coming in on requests. We abstract the request/response handling with koa controllers / unary grpc functions, and share the logic after that.
The interfaces we make for use with the koa controller and service functions overlap exactly with the proto messages we write coming from grpc. However the types generated (the "permissive" type) has all properties optional.
There is a "restrictive" type, but it's always the message name with "__Output" on the end, which makes it very long and clunky to use.
We never want to use the permissive type. If we wanted optional properties, we would mark them as optional in the proto.
Describe the solution you'd like
A flag to suppress the output of the "permissive" type and to make the "restrictive" type use the name the permissive type would have.
Describe alternatives you've considered
Telling developers to always import the __Output restrictive type is what we've been doing, but this has to be enforced in code review. If the permissive type wasn't generated at all, then it removes the need to look out for this.
Additional context
TypeScript doesn't think the types overlap
Proto file:
message UpdateLocationRequest {
int32 locationId = 1;
string name = 2;
string description = 3;
string locationNumber = 4;
string line1 = 5;
string line2 = 6;
string city = 7;
string state = 8;
string postal = 9;
int32 latitude = 10;
int32 longitude = 11;
string timezone = 12;
}
Generated types (from proto-loader-gen-types):
export interface UpdateLocationRequest {
'locationId'?: (number);
'name'?: (string);
'description'?: (string);
'locationNumber'?: (string);
'line1'?: (string);
'line2'?: (string);
'city'?: (string);
'state'?: (string);
'postal'?: (string);
'latitude'?: (number);
'longitude'?: (number);
'timezone'?: (string);
}
export interface UpdateLocationRequest__Output {
'locationId': (number);
'name': (string);
'description': (string);
'locationNumber': (string);
'line1': (string);
'line2': (string);
'city': (string);
'state': (string);
'postal': (string);
'latitude': (number);
'longitude': (number);
'timezone': (string);
}
Our Typescript interface (for koa controllers/service):
export interface LocationUpdate {
name: string;
description: string;
locationNumber: string;
line1: string;
line2?: string;
city: string;
state: string;
postal: string;
latitude: number;
longitude: number;
timezone: string;
}
Usage:
// service function
const updateLocation = async (locationId: number, location: LocationUpdate): Promise<void> => {
// ...
};
// koa controller
const updateLocationController = async (ctx: Context<LocationUpdate, void>) => {
const { locationId } = ctx.params;
await updateLocation(locationId, ctx.request.body);
};
// grpc unary handler
const updateLocationGrpcHandler = async (req: UpdateLocationRequest): Promise<void> => {
const { locationId, ...location } = req;
// type error here
await updateLocation(locationId, location);
};
Type error:
Argument of type '{ name?: string; description?: string; locationNumber?: string; line1?: string; line2?: string; city?: string; state?: string; postal?: string; latitude?: number; longitude?: number; timezone?: string; }' is not assignable to parameter of type 'LocationUpdate'.
Property 'name' is optional in type '{ name?: string; description?: string; locationNumber?: string; line1?: string; line2?: string; city?: string; state?: string; postal?: string; latitude?: number; longitude?: number; timezone?: string; }' but required in type 'LocationUpdate'.ts(2345)
Using restrictive type eliminates the error since the properties are not optional:
const updateLocationGrpcHandler = async (req: UpdateLocationRequest__Output): Promise<void> => {
const { locationId, ...location } = req;
// no more error
await updateLocation(locationId, location);
};
- 主要言語
- TypeScript
- スター
- 4.8k
- フォーク
- 717
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 17
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
grpc/grpc-node のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 2 日以内に返信
-
package: @grpc/grpc-js
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
grpc/grpc-node#2993 · コメント 3 件 · リアクション 4 件 ·
メンテナーはふだん 2 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
grpc/grpc-node#3091 · リアクション 1 件 ·
メンテナーはふだん 2 日以内に返信
-
feature request
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
grpc/grpc-node#3077 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 76/100
grpc/grpc-node#3068 · コメント 2 件 · リアクション 1 件 ·
メンテナーはふだん 2 日以内に返信
似ている issue
-
Mend: dependency security vulnerability untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
opensearch-project/security-dashboards-plugin#2545 ·
メンテナーはふだん 1 日以内に返信
-
Add: Dream TR SDオープンcheck:passed streams:add
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
doctor integrity sample scans soft-deleted pages on Postgres (batch path has no deleted_at filter)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
SocialGouv/egapro#4672 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
area:agents area:tui bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
anthropics/claude-code#98358 ·
メンテナーはふだん 1 日以内に返信