From ec27cc6eb8eb949758ce295e96bf79567b3bf04d Mon Sep 17 00:00:00 2001 From: gcanti Date: Wed, 25 Oct 2023 09:22:20 +0200 Subject: [PATCH] Schema: `split` should support subtypes of `string` --- .changeset/flat-ears-trade.md | 5 +++++ dtslint/Schema.ts | 8 ++++++++ src/Schema.ts | 9 +++++---- 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 .changeset/flat-ears-trade.md diff --git a/.changeset/flat-ears-trade.md b/.changeset/flat-ears-trade.md new file mode 100644 index 000000000..7f6703995 --- /dev/null +++ b/.changeset/flat-ears-trade.md @@ -0,0 +1,5 @@ +--- +"@effect/schema": patch +--- + +Schema: `split` should support subtypes of `string` diff --git a/dtslint/Schema.ts b/dtslint/Schema.ts index cc55034e0..6a6041759 100644 --- a/dtslint/Schema.ts +++ b/dtslint/Schema.ts @@ -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(':')) diff --git a/src/Schema.ts b/src/Schema.ts index 7009bc5c5..cb2f4e31f 100644 --- a/src/Schema.ts +++ b/src/Schema.ts @@ -1790,16 +1790,17 @@ export const trim = (self: Schema): Schema => * @since 1.0.0 */ export const split: { - (separator: string): (self: Schema) => Schema> - (self: Schema, separator: string): Schema> + (separator: string): (self: Schema) => Schema> + (self: Schema, separator: string): Schema> } = dual( 2, - (self: Schema, separator: string): Schema> => + (self: Schema, separator: string): Schema> => transform( self, array(string), S.split(separator), - ReadonlyArray.join(separator) + ReadonlyArray.join(separator), + { strict: false } ) )