SemVer: narrow isPrerelease to SemVer.Prerelease and reject sparse identifier arrays
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Written by an AI agent (Antigravity) on behalf of @jasonkuhrt.
Make SemVer.isPrerelease a type guard ((self: SemVer) => self is Prerelease) narrowing prerelease to Array.NonEmptyReadonlyArray<string | number>, export the SemVer.Prerelease interface, and reject sparse identifier arrays in SemVer.make, withPrerelease, and withBuild.
Context
effect/SemVer (added in #9243, currently @stability unstable in [email protected] and on main at 584c9e090) defines isPrerelease as returning plain boolean:
export const isPrerelease = (self: SemVer): boolean => self.prerelease.length > 0
Because it does not narrow, callers who have already checked SemVer.isPrerelease(version) still see version.prerelease as ReadonlyArray<string | number>, so non-empty operations fail to type-check without a redundant check:
import { Array, SemVer } from "effect"
const version = SemVer.parseUnsafe("2.0.0-rc.1")
if (SemVer.isPrerelease(version)) {
// TS2345 on [email protected] and main (584c9e090):
// Argument of type 'readonly (string | number)[]' is not assignable to
// parameter of type 'readonly [string | number, ...(string | number)[]]'
Array.headNonEmpty(version.prerelease)
}
In addition, SemVer.make, withPrerelease, and withBuild currently validate identifier arrays with .map(...), which preserves sparse array holes: passing new Array<string>(1) produces a SemVer where isPrerelease is true, prerelease[0] is undefined, and SemVer.format returns "1.0.0-". Validating indexed entries with an explicit loop and a typeof identifier !== "string" check rejects sparse holes so Prerelease.prerelease is sound at runtime too.
Proposed change
Export Prerelease as a sub-interface of SemVer and narrow isPrerelease to it:
export interface Prerelease extends SemVer {
readonly prerelease: NonEmptyReadonlyArray<string | number>
}
export const isPrerelease = (self: SemVer): self is Prerelease =>
self.prerelease.length > 0
With this change:
import { Array, SemVer } from "effect"
const versions = ["1.0.0", "2.0.0-rc.1", "2.0.0-beta.3"].map(SemVer.parseUnsafe)
// Array<SemVer.Prerelease> -> ["rc", "beta"]
Array.filter(versions, SemVer.isPrerelease).map((version) =>
Array.headNonEmpty(version.prerelease)
)
Compatibility
isPrerelease remains assignable to (self: SemVer) => boolean and Prerelease is assignable to SemVer, but narrowing changes the inferred return type of calls like Array.filter(versions, SemVer.isPrerelease) from Array<SemVer.SemVer> to Array<SemVer.Prerelease>. Code that mutates that array by pushing an un-narrowed SemVer (e.g. from SemVer.parseUnsafe) fails with TS2345 unless annotated as Array<SemVer.SemVer>. Under Effect's @stability unstable policy, that makes this a minor release change.
For a separate discussion on splitting SemVer itself into Release | Prerelease so the else branch narrows too, see #11050.
- Ngôn ngữ chính
- TypeScript
- Star
- 16.7k
- Fork
- 808
- Merge trung bình
- 21 giờ 22 phút
- Pull request đã merge (30 ngày)
- 486
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Effect-TS/effect
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
`@effect/ui-native` (Effect-TS/ui): `kit/VirtualList` `list` part widens `R` to `any`, poisoning enclosing componentsCó thể đã có người làm @effect-bot đã nhận hôm nay. Đang mở
Effect-TS/effect#11097 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`@effect/ui-native` (Effect-TS/ui): Controlled `input` rejected-edit restore never calls `host.commit()`Có thể đã có người làm @effect-bot đã nhận hôm nay. Đang mở
Effect-TS/effect#11096 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của Effect-TS/effect
Issue tương tự
-
check:failed streams:edit
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
iptv-org/iptv#60585 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: Critical path skips a child span that ends exactly when the next one startsCó thể đã có người làm @Piyush4801 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
jaegertracing/jaeger-ui#4865 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
anthropics/claude-code#112972 ·
-
Type: Improvement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày