effect
effect copied to clipboard
Improve opaque inheriting brands
What is the problem this feature would solve?
What is the feature you are proposing to solve the problem?
Some small changes to the types:
export type Brands<P> = P extends Brand<any> ? Types.UnionToIntersection<
{
[k in keyof P[BrandTypeId]]: k extends string | symbol ? Brand<k>
: never
}[keyof P[BrandTypeId]]
>
: never
->
export type Brands<P> = P extends B.Brand<any> ? { readonly [B.BrandTypeId]: P[B.BrandTypeId] }
: never
https://github.com/effect-ts-app/libs/blob/main/packages/schema/src/brand.ts https://github.com/effect-ts-app/libs/blob/main/packages/schema/src/strings.ts#L38
What alternatives have you considered?
No response
AFAIK, this is not an issue with schema, but rather related to the effect/Brand module, minimal repro:
import type * as Brand from "effect/Brand"
import type { Simplify } from "effect/Types"
export type WithType = Brand.Brand<"B"> & Brand.Brand<"A">
// type Test1 = string
export type Test1 = Brand.Brand.Unbranded<string & WithType>
export interface WithInterface extends Simplify<Brand.Brand<"B"> & Brand.Brand<"A">> {}
// type Test2 = string & BBrand_Interface
export type Test2 = Brand.Brand.Unbranded<string & WithInterface>
AFAIK, this is not an issue with schema, but rather related to the
effect/Brandmodule, minimal repro:
you're right.
and interestingly, the type adjustment fixes the Test2 case, but breaks the Test1 case.