Type-check the ports passed to `getMappedPort`
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 68/100
- issue の種類
- 機能追加
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- docker, node.js, typescript
調査の方向性
Start by reading withExposedPorts and start in packages/testcontainers/src/test-container.ts and packages/testcontainers/src/generic-container/generic-container.ts, then inspect getMappedPort on StartedTestContainer. Check the repository’s existing TypeScript type tests and add cases for literal exposed ports, UDP ports, repeated calls, and dynamic ports. Done means exposed literal ports are type-checked while dynamic ports retain current behavior; coordinate the interface changes with #1529 and #1563.
索引モデルが issue の本文から書いたものです。
説明
What happens
getMappedPort accepts any number. Asking for a port that was never exposed compiles, and fails when the test runs:
const container = await new GenericContainer(image).withExposedPorts(8080).start();
container.getMappedPort(8081); // compiles
// Error: No port binding found for :8081/tcp
The mistake is usually a typo, or a port constant that drifted from the one passed to withExposedPorts.
Expected
The ports given to withExposedPorts are carried in the builder's type, and getMappedPort on the started container accepts only those:
const container = await new GenericContainer(image).withExposedPorts(8080, "53/udp").start();
container.getMappedPort(8080);
container.getMappedPort(53, "udp");
container.getMappedPort(8081); // compile error
Where the ports are not known statically, nothing changes: getMappedPort accepts any number, as it does today.
Where
withExposedPortsandstartinpackages/testcontainers/src/test-container.tsandpackages/testcontainers/src/generic-container/generic-container.tsgetMappedPortonStartedTestContainer
Notes
A prototype of the types compiles under the repo's TypeScript (7.0.2) with these cases checked. It needs no class type parameter, so the fluent this return type and module subclasses are unaffected:
declare const exposed: unique symbol;
type Exposed<P extends number> = { readonly [exposed]: { readonly [K in P]: true } };
type PortsOf<T> = T extends { readonly [exposed]: infer M } ? keyof M & number : number;
interface StartedTestContainer<P extends number = number> {
getMappedPort(port: P, protocol?: string): number;
getMappedPort(portWithProtocol: `${P}/${"tcp" | "udp"}`): number;
}
class GenericContainer {
withExposedPorts<const T extends PortWithOptionalBinding[]>(...ports: T): this & Exposed<ContainerPort<T[number]>>;
start(): Promise<StartedTestContainer<PortsOf<this>>>;
}
- Each
withExposedPortscall intersects a marker ontothis. Laterwith*calls returnthis, so the marker survives the rest of the chain, and repeated calls accumulate. - It falls back to
number, and so to today's behaviour, when a port is anumbervariable, when the builder is stored in a variable typedGenericContainer, and whenwithExposedPortswas never called. - Module containers are unaffected, because their
start()returns their own started type. A module could opt in later. - Ports that a subclass exposes in its constructor or hooks are not visible to the caller's type.
- The
consttype parameter needs TypeScript 5.0 or later in consuming projects. Without it, only the object form ({ container, host }) loses precision. - The intersection shows up in editor hovers, for example
GenericContainer & Exposed<8080 | 53>. - Changing the signature on the
TestContainerinterface is a compile error for anyone who implements that interface without extendingGenericContainer.
Dependencies
- Nothing blocks this. It can start now.
- Coordinate with #1529: both change the
TestContainerinterface. - Coordinate with #1563: the started type gains a type parameter, which the forwarding wrapper has to pass through until it is removed.
- 主要言語
- TypeScript
- スター
- 2.6k
- フォーク
- 274
- 平均マージ
- 1日 14時間
- マージ済み PR(30日)
- 44
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
testcontainers/testcontainers-node のほかの issue
-
enhancement minor
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
testcontainers/testcontainers-node#1539 ·
メンテナーはふだん 1 日以内に返信
-
enhancement minor
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
testcontainers/testcontainers-node#1533 ·
メンテナーはふだん 1 日以内に返信
-
enhancement minor
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
testcontainers/testcontainers-node#1531 ·
メンテナーはふだん 1 日以内に返信
-
enhancement minor
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
testcontainers/testcontainers-node#1529 ·
メンテナーはふだん 1 日以内に返信
-
enhancement minor
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
testcontainers/testcontainers-node#1528 ·
メンテナーはふだん 1 日以内に返信
testcontainers/testcontainers-node の issue をすべて見る
似ている issue
-
afk-ok area:data-quality importer size:S
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
enorm-labs/event-junkie#3301 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
one-zero-eight/apply-bot#39 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
bigbluebutton/bbb-ui-components-react#108 ·
メンテナーはふだん 2 日以内に返信
-
area: app type: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
ExpidetGames/code-reviewer#308 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信