From 6921c4fb8c45badff09b493043b85ca71302b560 Mon Sep 17 00:00:00 2001 From: Giulio Canti Date: Sat, 20 Jul 2024 15:04:30 +0200 Subject: [PATCH] Remove incorrect static override type annotations in class definitions (#3311) --- .changeset/quick-zebras-thank.md | 7 + packages/schema/dtslint/Schema.ts | 3 - packages/schema/src/Schema.ts | 226 +++++++----------------------- 3 files changed, 61 insertions(+), 175 deletions(-) create mode 100644 .changeset/quick-zebras-thank.md diff --git a/.changeset/quick-zebras-thank.md b/.changeset/quick-zebras-thank.md new file mode 100644 index 0000000000..df2d52e3bd --- /dev/null +++ b/.changeset/quick-zebras-thank.md @@ -0,0 +1,7 @@ +--- +"@effect/schema": patch +--- + +Remove incorrect static override type annotations in class definitions. + +This will also improve tree-shakeability. diff --git a/packages/schema/dtslint/Schema.ts b/packages/schema/dtslint/Schema.ts index cac0889c2f..96226dcebb 100644 --- a/packages/schema/dtslint/Schema.ts +++ b/packages/schema/dtslint/Schema.ts @@ -49,9 +49,6 @@ hole>() // @ts-expect-error S.String.annotations({ a: 1 }) -// $ExpectType typeof String$ -S.String.annotations({ [Symbol.for("a")]: 1 }) - /** * @category api interface * @since 1.0.0 diff --git a/packages/schema/src/Schema.ts b/packages/schema/src/Schema.ts index c4a4a2fb94..a2625e44f8 100644 --- a/packages/schema/src/Schema.ts +++ b/packages/schema/src/Schema.ts @@ -939,85 +939,61 @@ export const instanceOf = any>( * @category primitives * @since 0.67.0 */ -export class Undefined extends make(AST.undefinedKeyword) { - static override annotations: (annotations: Annotations.Schema) => typeof Undefined = super.annotations -} +export class Undefined extends make(AST.undefinedKeyword) {} /** * @category primitives * @since 0.67.0 */ -export class Void extends make(AST.voidKeyword) { - static override annotations: (annotations: Annotations.Schema) => typeof Void = super.annotations -} +export class Void extends make(AST.voidKeyword) {} /** * @category primitives * @since 0.67.0 */ -export class Null extends make(AST.null) { - static override annotations: (annotations: Annotations.Schema) => typeof Null = super.annotations -} +export class Null extends make(AST.null) {} /** * @category primitives * @since 0.67.0 */ -export class Never extends make(AST.neverKeyword) { - static override annotations: (annotations: Annotations.Schema) => typeof Never = super.annotations -} +export class Never extends make(AST.neverKeyword) {} /** * @category primitives * @since 0.67.0 */ -export class Unknown extends make(AST.unknownKeyword) { - static override annotations: (annotations: Annotations.Schema) => typeof Unknown = super.annotations -} +export class Unknown extends make(AST.unknownKeyword) {} /** * @category primitives * @since 0.67.0 */ -export class Any extends make(AST.anyKeyword) { - static override annotations: (annotations: Annotations.Schema) => typeof Any = super.annotations -} +export class Any extends make(AST.anyKeyword) {} /** * @category primitives * @since 0.67.0 */ -export class BigIntFromSelf extends make(AST.bigIntKeyword) { - static override annotations: (annotations: Annotations.Schema) => typeof BigIntFromSelf = super.annotations -} +export class BigIntFromSelf extends make(AST.bigIntKeyword) {} /** * @category primitives * @since 0.67.0 */ -export class SymbolFromSelf extends make(AST.symbolKeyword) { - static override annotations: (annotations: Annotations.Schema) => typeof SymbolFromSelf = super.annotations -} +export class SymbolFromSelf extends make(AST.symbolKeyword) {} /** @ignore */ -class String$ extends make(AST.stringKeyword) { - static override annotations: (annotations: Annotations.Schema) => typeof String$ = super.annotations -} +class String$ extends make(AST.stringKeyword) {} /** @ignore */ -class Number$ extends make(AST.numberKeyword) { - static override annotations: (annotations: Annotations.Schema) => typeof Number$ = super.annotations -} +class Number$ extends make(AST.numberKeyword) {} /** @ignore */ -class Boolean$ extends make(AST.booleanKeyword) { - static override annotations: (annotations: Annotations.Schema) => typeof Boolean$ = super.annotations -} +class Boolean$ extends make(AST.booleanKeyword) {} /** @ignore */ -class Object$ extends make(AST.objectKeyword) { - static override annotations: (annotations: Annotations.Schema) => typeof Object$ = super.annotations -} +class Object$ extends make(AST.objectKeyword) {} export { /** @@ -4005,9 +3981,7 @@ export const lowercased = */ export class Lowercased extends String$.pipe( lowercased({ identifier: "Lowercased", title: "Lowercased" }) -) { - static override annotations: (annotations: Annotations.Schema) => typeof Lowercased = super.annotations -} +) {} /** * @category type id @@ -4037,9 +4011,7 @@ export const capitalized = */ export class Capitalized extends String$.pipe( capitalized({ identifier: "Capitalized", title: "Capitalized" }) -) { - static override annotations: (annotations: Annotations.Schema) => typeof Capitalized = super.annotations -} +) {} /** * @category type id @@ -4069,9 +4041,7 @@ export const uncapitalized = */ export class Uncapitalized extends String$.pipe( uncapitalized({ identifier: "Uncapitalized", title: "Uncapitalized" }) -) { - static override annotations: (annotations: Annotations.Schema) => typeof Uncapitalized = super.annotations -} +) {} /** * @category type id @@ -4101,9 +4071,7 @@ export const uppercased = */ export class Uppercased extends String$.pipe( uppercased({ identifier: "Uppercased", title: "Uppercased" }) -) { - static override annotations: (annotations: Annotations.Schema) => typeof Uppercased = super.annotations -} +) {} /** * @category type id @@ -4154,9 +4122,7 @@ export const length = ( * @category string constructors * @since 0.67.0 */ -export class Char extends String$.pipe(length(1, { identifier: "Char" })) { - static override annotations: (annotations: Annotations.Schema) => typeof Char = super.annotations -} +export class Char extends String$.pipe(length(1, { identifier: "Char" })) {} /** * @category string filters @@ -4180,9 +4146,7 @@ export class Lowercase extends transform( String$, Lowercased, { strict: true, decode: (s) => s.toLowerCase(), encode: identity } -).annotations({ identifier: "Lowercase" }) { - static override annotations: (annotations: Annotations.Schema) => typeof Lowercase = super.annotations -} +).annotations({ identifier: "Lowercase" }) {} /** * This schema converts a string to uppercase. @@ -4194,9 +4158,7 @@ export class Uppercase extends transform( String$, Uppercased, { strict: true, decode: (s) => s.toUpperCase(), encode: identity } -).annotations({ identifier: "Uppercase" }) { - static override annotations: (annotations: Annotations.Schema) => typeof Uppercase = super.annotations -} +).annotations({ identifier: "Uppercase" }) {} /** * This schema converts a string to capitalized one. @@ -4208,9 +4170,7 @@ export class Capitalize extends transform( String$, Capitalized, { strict: true, decode: (s) => string_.capitalize(s), encode: identity } -).annotations({ identifier: "Capitalize" }) { - static override annotations: (annotations: Annotations.Schema) => typeof Capitalize = super.annotations -} +).annotations({ identifier: "Capitalize" }) {} /** * This schema converts a string to uncapitalized one. @@ -4222,9 +4182,7 @@ export class Uncapitalize extends transform( String$, Uncapitalized, { strict: true, decode: (s) => string_.uncapitalize(s), encode: identity } -).annotations({ identifier: "Uncapitalize" }) { - static override annotations: (annotations: Annotations.Schema) => typeof Uncapitalize = super.annotations -} +).annotations({ identifier: "Uncapitalize" }) {} /** * @category string constructors @@ -4232,9 +4190,7 @@ export class Uncapitalize extends transform( */ export class Trimmed extends String$.pipe( trimmed({ identifier: "Trimmed", title: "Trimmed" }) -) { - static override annotations: (annotations: Annotations.Schema) => typeof Trimmed = super.annotations -} +) {} /** * This schema allows removing whitespaces from the beginning and end of a string. @@ -4246,9 +4202,7 @@ export class Trim extends transform( String$, Trimmed, { strict: true, decode: (s) => s.trim(), encode: identity } -).annotations({ identifier: "Trim" }) { - static override annotations: (annotations: Annotations.Schema) => typeof Trim = super.annotations -} +).annotations({ identifier: "Trim" }) {} /** * Returns a schema that allows splitting a string into an array of strings. @@ -4328,9 +4282,7 @@ export const parseJson: { */ export class NonEmpty extends String$.pipe( nonEmpty({ identifier: "NonEmpty", title: "NonEmpty" }) -) { - static override annotations: (annotations: Annotations.Schema) => typeof NonEmpty = super.annotations -} +) {} /** * @category type id @@ -4356,9 +4308,7 @@ export class UUID extends String$.pipe( description: "a Universally Unique Identifier", arbitrary: (): LazyArbitrary => (fc) => fc.uuid() }) -) { - static override annotations: (annotations: Annotations.Schema) => typeof UUID = super.annotations -} +) {} /** * @category type id @@ -4385,9 +4335,7 @@ export class ULID extends String$.pipe( description: "a Universally Unique Lexicographically Sortable Identifier", arbitrary: (): LazyArbitrary => (fc) => fc.ulid() }) -) { - static override annotations: (annotations: Annotations.Schema) => typeof ULID = super.annotations -} +) {} /** * @category type id @@ -4724,33 +4672,25 @@ export const parseNumber = ( * @category number constructors * @since 0.67.0 */ -export class NumberFromString extends parseNumber(String$).annotations({ identifier: "NumberFromString" }) { - static override annotations: (annotations: Annotations.Schema) => typeof NumberFromString = super.annotations -} +export class NumberFromString extends parseNumber(String$).annotations({ identifier: "NumberFromString" }) {} /** * @category number constructors * @since 0.67.0 */ -export class Finite extends Number$.pipe(finite({ identifier: "Finite", title: "Finite" })) { - static override annotations: (annotations: Annotations.Schema) => typeof Finite = super.annotations -} +export class Finite extends Number$.pipe(finite({ identifier: "Finite", title: "Finite" })) {} /** * @category number constructors * @since 0.67.0 */ -export class Int extends Number$.pipe(int({ identifier: "Int", title: "Int" })) { - static override annotations: (annotations: Annotations.Schema) => typeof Int = super.annotations -} +export class Int extends Number$.pipe(int({ identifier: "Int", title: "Int" })) {} /** * @category number constructors * @since 0.67.0 */ -export class NonNaN extends Number$.pipe(nonNaN({ identifier: "NonNaN", title: "NonNaN" })) { - static override annotations: (annotations: Annotations.Schema) => typeof NonNaN = super.annotations -} +export class NonNaN extends Number$.pipe(nonNaN({ identifier: "NonNaN", title: "NonNaN" })) {} /** * @category number constructors @@ -4758,9 +4698,7 @@ export class NonNaN extends Number$.pipe(nonNaN({ identifier: "NonNaN", title: " */ export class Positive extends Number$.pipe( positive({ identifier: "Positive", title: "Positive" }) -) { - static override annotations: (annotations: Annotations.Schema) => typeof Positive = super.annotations -} +) {} /** * @category number constructors @@ -4768,9 +4706,7 @@ export class Positive extends Number$.pipe( */ export class Negative extends Number$.pipe( negative({ identifier: "Negative", title: "Negative" }) -) { - static override annotations: (annotations: Annotations.Schema) => typeof Negative = super.annotations -} +) {} /** * @category number constructors @@ -4778,9 +4714,7 @@ export class Negative extends Number$.pipe( */ export class NonPositive extends Number$.pipe( nonPositive({ identifier: "NonPositive", title: "NonPositive" }) -) { - static override annotations: (annotations: Annotations.Schema) => typeof NonPositive = super.annotations -} +) {} /** * @category number constructors @@ -4788,9 +4722,7 @@ export class NonPositive extends Number$.pipe( */ export class NonNegative extends Number$.pipe( nonNegative({ identifier: "NonNegative", title: "NonNegative" }) -) { - static override annotations: (annotations: Annotations.Schema) => typeof NonNegative = super.annotations -} +) {} /** * @category type id @@ -4824,26 +4756,20 @@ export class JsonNumber extends Number$.pipe( description: "a JSON-compatible number, excluding NaN, +Infinity, and -Infinity", jsonSchema: { type: "number" } }) -) { - static override annotations: (annotations: Annotations.Schema) => typeof JsonNumber = super.annotations -} +) {} /** * @category boolean transformations * @since 0.67.0 */ -export class Not extends transform(Boolean$, Boolean$, { strict: true, decode: boolean_.not, encode: boolean_.not }) { - static override annotations: (annotations: Annotations.Schema) => typeof Not = super.annotations -} +export class Not extends transform(Boolean$, Boolean$, { strict: true, decode: boolean_.not, encode: boolean_.not }) {} /** @ignore */ class Symbol$ extends transform( String$, SymbolFromSelf, { strict: false, decode: (s) => Symbol.for(s), encode: (sym) => sym.description } -).annotations({ identifier: "symbol" }) { - static override annotations: (annotations: Annotations.Schema) => typeof Symbol$ = super.annotations -} +).annotations({ identifier: "symbol" }) {} export { /** @@ -5059,9 +4985,7 @@ class BigInt$ extends transformOrFail( decode: (s, _, ast) => ParseResult.fromOption(bigInt_.fromString(s), () => new ParseResult.Type(ast, s)), encode: (n) => ParseResult.succeed(String(n)) } -).annotations({ identifier: "bigint" }) { - static override annotations: (annotations: Annotations.Schema) => typeof BigInt$ = super.annotations -} +).annotations({ identifier: "bigint" }) {} export { /** @@ -5159,9 +5083,7 @@ export class BigIntFromNumber extends transformOrFail( ), encode: (b, _, ast) => ParseResult.fromOption(bigInt_.toNumber(b), () => new ParseResult.Type(ast, b)) } -).annotations({ identifier: "BigintFromNumber" }) { - static override annotations: (annotations: Annotations.Schema) => typeof BigIntFromNumber = super.annotations -} +).annotations({ identifier: "BigintFromNumber" }) {} const redactedArbitrary = (value: LazyArbitrary): LazyArbitrary> => (fc) => value(fc).map((x) => redacted_.make(x)) @@ -5275,10 +5197,7 @@ export class DurationFromSelf extends declare( ), equivalence: (): Equivalence.Equivalence => duration_.Equivalence } -) { - static override annotations: (annotations: Annotations.Schema) => typeof DurationFromSelf = super - .annotations -} +) {} /** * A schema that transforms a `bigint` tuple into a `Duration`. @@ -5299,10 +5218,7 @@ export class DurationFromNanos extends transformOrFail( onSome: (val) => ParseResult.succeed(val) }) } -).annotations({ identifier: "DurationFromNanos" }) { - static override annotations: (annotations: Annotations.Schema) => typeof DurationFromNanos = super - .annotations -} +).annotations({ identifier: "DurationFromNanos" }) {} /** * A schema that transforms a `number` tuple into a `Duration`. @@ -5315,10 +5231,7 @@ export class DurationFromMillis extends transform( Number$, DurationFromSelf, { strict: true, decode: (ms) => duration_.millis(ms), encode: (n) => duration_.toMillis(n) } -).annotations({ identifier: "DurationFromMillis" }) { - static override annotations: (annotations: Annotations.Schema) => typeof DurationFromMillis = - super.annotations -} +).annotations({ identifier: "DurationFromMillis" }) {} const hrTime: Schema = Tuple( NonNegative.pipe( @@ -5349,10 +5262,7 @@ export class Duration extends transform( decode: ([seconds, nanos]) => duration_.nanos(BigInt(seconds) * BigInt(1e9) + BigInt(nanos)), encode: (duration) => duration_.toHrTime(duration) } -).annotations({ identifier: "Duration" }) { - static override annotations: (annotations: Annotations.Schema) => typeof Duration = super - .annotations -} +).annotations({ identifier: "Duration" }) {} /** * Clamps a `Duration` between a minimum and a maximum value. @@ -5768,9 +5678,7 @@ export class DateFromSelf extends declare( arbitrary: (): LazyArbitrary => (fc) => fc.date({ noInvalidDate: false }), equivalence: () => Equivalence.Date } -) { - static override annotations: (annotations: Annotations.Schema) => typeof DateFromSelf = super.annotations -} +) {} /** * Defines a schema that ensures only valid dates are accepted. This schema @@ -5787,9 +5695,7 @@ export class ValidDateFromSelf extends DateFromSelf.pipe( identifier: "ValidDateFromSelf", description: "a valid Date instance" }) -) { - static override annotations: (annotations: Annotations.Schema) => typeof ValidDateFromSelf = super.annotations -} +) {} /** * Defines a schema that attempts to convert a `string` to a `Date` object using @@ -5804,16 +5710,12 @@ export class DateFromString extends transform( String$, DateFromSelf, { strict: true, decode: (s) => new Date(s), encode: (d) => d.toISOString() } -).annotations({ identifier: "DateFromString" }) { - static override annotations: (annotations: Annotations.Schema) => typeof DateFromString = super.annotations -} +).annotations({ identifier: "DateFromString" }) {} /** @ignore */ class Date$ extends DateFromString.pipe( validDate({ identifier: "Date" }) -) { - static override annotations: (annotations: Annotations.Schema) => typeof Date$ = super.annotations -} +) {} export { /** @@ -5842,9 +5744,7 @@ export class DateFromNumber extends transform( Number$, DateFromSelf, { strict: true, decode: (n) => new Date(n), encode: (d) => d.getTime() } -).annotations({ identifier: "DateFromNumber" }) { - static override annotations: (annotations: Annotations.Schema) => typeof DateFromNumber = super.annotations -} +).annotations({ identifier: "DateFromNumber" }) {} /** * @category Option utils @@ -6615,10 +6515,7 @@ export class BigDecimalFromSelf extends declare( arbitrary: bigDecimalArbitrary, equivalence: () => bigDecimal_.Equivalence } -) { - static override annotations: (annotations: Annotations.Schema) => typeof BigDecimalFromSelf = - super.annotations -} +) {} /** * @category BigDecimal transformations @@ -6636,10 +6533,7 @@ export class BigDecimal extends transformOrFail( })), encode: (val) => ParseResult.succeed(bigDecimal_.format(bigDecimal_.normalize(val))) } -).annotations({ identifier: "BigDecimal" }) { - static override annotations: (annotations: Annotations.Schema) => typeof BigDecimal = super - .annotations -} +).annotations({ identifier: "BigDecimal" }) {} /** * A schema that transforms a `number` into a `BigDecimal`. @@ -6656,11 +6550,7 @@ export class BigDecimalFromNumber extends transformOrFail( decode: (num) => ParseResult.succeed(bigDecimal_.fromNumber(num)), encode: (val) => ParseResult.succeed(bigDecimal_.unsafeToNumber(val)) } -).annotations({ identifier: "BigDecimalFromNumber" }) { - static override annotations: ( - annotations: Annotations.Schema - ) => typeof BigDecimalFromNumber = super.annotations -} +).annotations({ identifier: "BigDecimalFromNumber" }) {} /** * @category type id @@ -7798,10 +7688,7 @@ export class FiberIdFromSelf extends declare( pretty: () => fiberIdPretty, arbitrary: () => fiberIdArbitrary } -) { - static override annotations: (annotations: Annotations.Schema) => typeof FiberIdFromSelf = super - .annotations -} +) {} const fiberIdDecode = (input: FiberIdEncoded): fiberId_.FiberId => { switch (input._tag) { @@ -7837,9 +7724,7 @@ export class FiberId extends transform( FiberIdEncoded, FiberIdFromSelf, { strict: true, decode: fiberIdDecode, encode: fiberIdEncode } -).annotations({ identifier: "FiberId" }) { - static override annotations: (annotations: Annotations.Schema) => typeof FiberId = super.annotations -} +).annotations({ identifier: "FiberId" }) {} /** * @category Cause utils @@ -8646,10 +8531,7 @@ export class BooleanFromUnknown extends transform( Unknown, Boolean$, { strict: true, decode: Predicate.isTruthy, encode: identity } -).annotations({ identifier: "BooleanFromUnknown" }) { - static override annotations: (annotations: Annotations.Schema) => typeof BooleanFromUnknown = super - .annotations -} +).annotations({ identifier: "BooleanFromUnknown" }) {} /** * @category Config validations