Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Add a flag for proto-loader-gen-types to only output the restrictive type and remove the "__Output" from the name

オープン
#2,839 コメント 5 件 リアクション 1 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
node.js, typescript
領域
api, tooling

調査の方向性

まず proto-loader-gen-types のエントリポイントと既存の生成オプションを特定し、次に permissive インターフェースと restrictive インターフェースが出力される箇所を追跡します。flag によって permissive インターフェースを抑制し、restrictive インターフェースにその名前を付けられ、生成された出力と関連する動作が検証されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

package: @grpc/proto-loader
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

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

grpc/grpc-node のほかの issue

grpc/grpc-node の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。