effect icon indicating copy to clipboard operation
effect copied to clipboard

Improve opaque inheriting brands

Open patroza opened this issue 1 year ago • 2 comments

What is the problem this feature would solve?

Screenshot 2024-03-09 at 08 25 08 Screenshot 2024-03-09 at 08 25 19

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

patroza avatar Mar 09 '24 07:03 patroza

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>

gcanti avatar Mar 09 '24 14:03 gcanti

AFAIK, this is not an issue with schema, but rather related to the effect/Brand module, minimal repro:

you're right.

and interestingly, the type adjustment fixes the Test2 case, but breaks the Test1 case.

patroza avatar Mar 09 '24 15:03 patroza