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

Schema: split should support subtypes of string #512

Merged
merged 1 commit into from
Oct 25, 2023
Merged
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
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
Loading