SemVer: consider splitting SemVer into Release | Prerelease while unstable

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

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

@effect-bot がすでに取り組んでいます。

2026年11月29日 から。

評価

この issue はまだ評価されていません。

説明

Written by an AI agent (Antigravity) on behalf of @jasonkuhrt.

Proposal: while effect/SemVer is still @stability unstable, consider splitting SemVer into a union Release | Prerelease (analogous to DateTime = Utc | Zoned) so callers can statically require stable releases and narrow both branches of SemVer.isPrerelease.

Context

On [email protected] and main (584c9e090, introduced in #9243), SemVer is a single flat interface:

export interface SemVer extends Pipeable, Equal.Equal, Inspectable {
  readonly [TypeId]: typeof TypeId
  readonly major: number
  readonly minor: number
  readonly patch: number
  readonly prerelease: ReadonlyArray<string | number>
  readonly build: ReadonlyArray<string>
}

Even with isPrerelease narrowed to a type guard (proposed separately in #11048 / #11049), a flat interface leaves two gaps:

import { Array, SemVer } from "effect"

declare function publishStable(version: SemVer.Release): void

const version = SemVer.parseUnsafe("2.0.0-rc.1")

if (SemVer.isPrerelease(version)) {
  Array.headNonEmpty(version.prerelease) // "rc"
  publishStable(SemVer.release(version)) // SemVer.release returns Release
} else {
  // With a union, `version` narrows to SemVer.Release here too;
  // with a flat interface it stays SemVer.
  publishStable(version)
}
Candidate shapes

Both variants keep SemVer.make({ ...version, patch: version.patch + 1 }), SemVerRange, Schema.SemVer, and array methods (.map, .filter, .reduce, .join, for...of) on version.prerelease working:

Aspect Variant A: structural (readonly []) Variant B: tagged (_tag, like DateTime)
Definition Release has readonly prerelease: readonly []; Prerelease has NonEmptyReadonlyArray<string | number>; type SemVer = Release | Prerelease Same as A, plus readonly _tag: "Release" / readonly _tag: "Prerelease" on instances
Two-way isPrerelease narrowing Yes (if -> Prerelease, else -> Release) Yes, plus v._tag === "Release" and Match.tag work natively
Operation return types release / bumpMajor / bumpMinor / bumpPatch can return Release; bumpPre* can return Prerelease Same
Runtime footprint Zero runtime change (including across mixed Effect versions sharing ~effect/SemVer) One own _tag property on instances (visible in Object.keys / spread; toJSON / inspect unchanged). If an untagged pre-4.2 SemVer crosses into isSemVer / fromInput in a dual-package setup, Variant B would either need a getter/re-tag or isSemVer to reject untagged values so Match.tagsExhaustive does not throw
Verified trade-offs (probed against main at 584c9e090)

Both variants pass pnpm check and the 763 SemVer/SemVerRange/Schema tests once internal Core in SemVer.ts stops using Pick<SemVer, ...> and types prerelease: ReadonlyArray<string | number> directly. Three consumer breaks surface under both variants:

  1. interface X extends SemVer.SemVer fails with TS2312 because an interface cannot extend a union type alias (callers must use an intersection or composition instead).
  2. version.prerelease[0] becomes string | number | undefined on an un-narrowed SemVer even without noUncheckedIndexedAccess (because (readonly [])[0] is undefined; on main it is string | number).
  3. Pick<SemVer, "prerelease"> becomes { readonly prerelease: readonly [] | NonEmptyReadonlyArray<string | number> }, rejecting plain ReadonlyArray<string | number> (the same error SemVerRange.ts hit on internal Core).

Under Effect's @stability unstable policy, those breaks make a union split a minor change — which is why #11049 keeps SemVer flat and this is opened separately for maintainer input. Totally fine if Effect prefers to keep SemVer flat; if maintainers want either variant, happy to follow up with a PR once a direction is agreed.

主要言語
TypeScript
スター
16.7k
フォーク
808
平均マージ
21時間 22分
マージ済み PR(30日)
486

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

Effect-TS/effect のほかの issue

Effect-TS/effect の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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