SemVer: narrow isPrerelease to SemVer.Prerelease and reject sparse identifier arrays
Los mantenedores suelen responder en 1 día
Evaluación
Este issue todavía no se ha evaluado.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 16.7k
- Forks
- 808
- Merge medio
- 21 h 22 min
- PR fusionados (30 d)
- 486
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Effect-TS/effect
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
`@effect/ui-native` (Effect-TS/ui): `kit/VirtualList` `list` part widens `R` to `any`, poisoning enclosing componentsPosiblemente ocupada @effect-bot la tomó hoy. Abierto
Effect-TS/effect#11097 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
`@effect/ui-native` (Effect-TS/ui): Controlled `input` rejected-edit restore never calls `host.commit()`Posiblemente ocupada @effect-bot la tomó hoy. Abierto
Effect-TS/effect#11096 · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de Effect-TS/effect
Issues similares
-
check:failed streams:edit
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
iptv-org/iptv#60585 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
Los mantenedores suelen responder en 1 día
-
[Bug]: Critical path skips a child span that ends exactly when the next one startsPosiblemente ocupada @Piyush4801 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
jaegertracing/jaeger-ui#4865 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
anthropics/claude-code#112972 ·
-
Type: Improvement
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día