Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
Schema: split should support subtypes of string (#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored Oct 25, 2023
1 parent 3d2e2b0 commit c1beed7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-ears-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/schema": patch
---

Schema: `split` should support subtypes of `string`
8 changes: 8 additions & 0 deletions dtslint/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,3 +630,11 @@ S.string.pipe(S.transformOrFail(S.number, s => ParseResult.success(s), n => Pars

// @ts-expect-error
S.string.pipe(S.transformOrFail(S.number, s => ParseResult.success(s.length), n => ParseResult.success(n)))

// ---------------------------------------------
// split
// ---------------------------------------------

// should support subtypes of `string`
// $ExpectType Schema<`a${string}`, readonly string[]>
S.templateLiteral(S.literal('a'), S.string).pipe(S.split(':'))
9 changes: 5 additions & 4 deletions src/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1790,16 +1790,17 @@ export const trim = <I, A extends string>(self: Schema<I, A>): Schema<I, A> =>
* @since 1.0.0
*/
export const split: {
(separator: string): <I>(self: Schema<I, string>) => Schema<I, ReadonlyArray<string>>
<I>(self: Schema<I, string>, separator: string): Schema<I, ReadonlyArray<string>>
(separator: string): <I, A extends string>(self: Schema<I, A>) => Schema<I, ReadonlyArray<string>>
<I, A extends string>(self: Schema<I, A>, separator: string): Schema<I, ReadonlyArray<string>>
} = dual(
2,
<I>(self: Schema<I, string>, separator: string): Schema<I, ReadonlyArray<string>> =>
<I, A extends string>(self: Schema<I, A>, separator: string): Schema<I, ReadonlyArray<string>> =>
transform(
self,
array(string),
S.split(separator),
ReadonlyArray.join(separator)
ReadonlyArray.join(separator),
{ strict: false }
)
)

Expand Down

0 comments on commit c1beed7

Please sign in to comment.