document tsconfig `lib`/`target` requirements

オープン
#112 コメント 9 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

  • #246 @ting-hong-shieh による — マージされずにクローズ

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
typescript
領域
api

調査の方向性

まず、RpcStub 型の定義と、newWebSocketRpcSession および newHttpBatchRpcSession のジェネリック宣言を見つけます。TypeScript の例で問題を再現し、ApiMessage のようなオブジェクトの戻り値の型が保持され、無効なプロパティが型チェックによって拒否されることを確認します。

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

説明

documentation

Description

When using newWebSocketRpcSession or newHttpBatchRpcSession with a TypeScript generic parameter, the RpcStub<T> type preserves primitive return types (string, number, boolean) but fails to preserve object/interface return types, returning any instead.

Minimal Reproducible Example

import { newWebSocketRpcSession, type RpcStub } from 'capnweb';

// Define types
type ApiMessage = { message: string; timestamp: string };

// Define API interface
interface MyApi {
  getPrimitive(): Promise<string>;           // Returns primitive
  getObject(): Promise<ApiMessage>;          // Returns object
  hello(name: string): Promise<ApiMessage>;  // Returns object
}

// Create client
const apiStub = newWebSocketRpcSession<MyApi>('wss://example.com/api');

// Primitives work correctly ✅
const primitive = await apiStub.getPrimitive();
//    ^? Type is 'string' ✅

// Objects return 'any' ❌
const object = await apiStub.getObject();
//    ^? Type is 'any' ❌

const helloResult = await apiStub.hello('world');
//    ^? Type is 'any' ❌

Expected Behavior

All method return types should be preserved, regardless of whether they're primitives or objects:

const primitive = await apiStub.getPrimitive();
//    ^? string ✅

const object = await apiStub.getObject();
//    ^? Should be: ApiMessage

const helloResult = await apiStub.hello('world');
//    ^? Should be: ApiMessage

Actual Behavior

Only primitive return types are preserved. Object/interface return types become any:

const apiStub: RpcStub<MyApi> = newWebSocketRpcSession<MyApi>('wss://example.com/api');
//    ^? Correctly shows: RpcStub<MyApi>

const primitive = await apiStub.getPrimitive();
//    ^? string ✅ Works!

const object = await apiStub.getObject();
//    ^? any ❌ Should be ApiMessage

const helloResult = await apiStub.hello('world');
//    ^? any ❌ Should be ApiMessage

// No type checking for objects
console.log(helloResult.anythingGoes); // No error

Root Cause

The RpcStub<T> type definition appears to handle primitives correctly but wraps object return types in complex proxy types (for promise pipelining support) that resolve to any instead of the original type.

Workaround

Manually cast each result:

const helloResult = await apiStub.hello('world') as ApiMessage;
//    ^? Now correctly typed as: ApiMessage ✅

Environment

  • capnweb version: 0.2.0
  • TypeScript version: 5.8.3
  • Node version: 22.15.1
主要言語
TypeScript
スター
4k
フォーク
151
平均マージ
16時間 46分
マージ済み PR(30日)
2

環境構築

はじめの一歩

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

cloudflare/capnweb のほかの issue

cloudflare/capnweb の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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