Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .changeset/flat-buttons-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
"effect": patch
---

Made Schema.brand keep type of schema being piped into it even if brand schema was extracted into a variable. Type was previously Schema.any

Before:

```ts
const UserIdBrandSchema = Schema.brand("UserId")
const UserIdSchema = pipe(Schema.Number, UserIdBrandSchema)
// ^? Schema.brand<Schema.Schema.Any, "UserId">
```

After:

```ts
const UserIdBrandSchema = Schema.brand("UserId")
const UserIdSchema = pipe(Schema.Number, UserIdBrandSchema)
// ^? Schema.brand<typeof Schema.Number, "UserId">
```
13 changes: 13 additions & 0 deletions packages/effect/dtslint/Schema/Brand.tst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,17 @@ describe("SchemaBrand", () => {
})
)
})

it("should not override types with any when extracted into a constant", () => {
const UserIdBrandSchema = Schema.brand("UserId")

const UserIdSchema = pipe(Schema.Number, UserIdBrandSchema)

type IUserId = Schema.Schema.Type<typeof UserIdSchema>

type IsAny<T> = 0 extends 1 & T ? true : false

expect<IsAny<IUserId>>().type.toBe<false>()
expect<IUserId>().type.toBeAssignableTo<number>()
})
})
2 changes: 1 addition & 1 deletion packages/effect/src/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3196,7 +3196,7 @@ export const brand = <S extends Schema.Any, B extends string | symbol>(
brand: B,
annotations?: Annotations.Schema<Schema.Type<S> & Brand<B>>
) =>
(self: S): brand<S, B> => {
<SubS extends S>(self: SubS): brand<SubS, B> => {
const annotation: AST.BrandAnnotation = option_.match(AST.getBrandAnnotation(self.ast), {
onNone: () => [brand],
onSome: (brands) => [...brands, brand]
Expand Down
Loading