SemVer: consider splitting SemVer into Release | Prerelease while unstable

未关闭
#11,050 0 条评论 0 个 reaction 已指派 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 分钟
30 天内合并 PR
486

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Effect-TS/effect 的其他 Issue

查看 Effect-TS/effect 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。