Skip to content

Commit

Permalink
Schema: remove the custom Simplify type that was previously introd… (
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored and tim-smart committed Mar 25, 2024
1 parent e1671a8 commit 1c20353
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-jobs-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/schema": patch
---

Removed the custom `Simplify` type that was previously introduced to address a bug in TypeScript 5.0
29 changes: 9 additions & 20 deletions packages/schema/src/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,6 @@ import * as Pretty from "./Pretty.js"
import type * as Serializable from "./Serializable.js"
import * as TreeFormatter from "./TreeFormatter.js"

/**
* Required to fix a bug in TypeScript@5.0, dtslint fails with:
* TypeScript@5.0 expected type to be:
* { readonly [x: string]: number; }
* got:
* { [x: string]: number; }
*
* @since 1.0.0
*/
export type Simplify<T> = { readonly [K in keyof T]: T[K] } & {}

/**
* @since 1.0.0
*/
Expand Down Expand Up @@ -1909,16 +1898,16 @@ export interface typeLiteral<
Records extends IndexSignature.Records
> extends
Schema<
Simplify<TypeLiteral.Type<Fields, Records>>,
Simplify<TypeLiteral.Encoded<Fields, Records>>,
Types.Simplify<TypeLiteral.Type<Fields, Records>>,
Types.Simplify<TypeLiteral.Encoded<Fields, Records>>,
| Struct.Context<Fields>
| IndexSignature.Context<Records>
>
{
readonly fields: { readonly [K in keyof Fields]: Fields[K] }
readonly records: Readonly<Records>
annotations(
annotations: Annotations.Schema<Simplify<TypeLiteral.Type<Fields, Records>>>
annotations: Annotations.Schema<Types.Simplify<TypeLiteral.Type<Fields, Records>>>
): typeLiteral<Fields, Records>
}

Expand All @@ -1929,8 +1918,8 @@ class $typeLiteral<
Fields extends Struct.Fields,
const Records extends IndexSignature.Records
> extends _schema.Schema<
Simplify<TypeLiteral.Type<Fields, Records>>,
Simplify<TypeLiteral.Encoded<Fields, Records>>,
Types.Simplify<TypeLiteral.Type<Fields, Records>>,
Types.Simplify<TypeLiteral.Encoded<Fields, Records>>,
| Struct.Context<Fields>
| IndexSignature.Context<Records>
> implements typeLiteral<Fields, Records> {
Expand Down Expand Up @@ -2022,7 +2011,7 @@ class $typeLiteral<
this.records = [...records] as Records
}
annotations(
annotations: Annotations.Schema<Simplify<TypeLiteral.Type<Fields, Records>>>
annotations: Annotations.Schema<Types.Simplify<TypeLiteral.Type<Fields, Records>>>
): typeLiteral<Fields, Records> {
return new $typeLiteral(this.fields, this.records, _schema.annotations(this.ast, annotations))
}
Expand All @@ -2033,7 +2022,7 @@ class $typeLiteral<
* @since 1.0.0
*/
export interface struct<Fields extends Struct.Fields> extends typeLiteral<Fields, []> {
annotations(annotations: Annotations.Schema<Simplify<Struct.Type<Fields>>>): struct<Fields>
annotations(annotations: Annotations.Schema<Types.Simplify<Struct.Type<Fields>>>): struct<Fields>
}

/**
Expand All @@ -2060,7 +2049,7 @@ export interface record<K extends Schema.All, V extends Schema.All> extends type
readonly key: K
readonly value: V
annotations(
annotations: Annotations.Schema<Simplify<TypeLiteral.Type<{}, [{ key: K; value: V }]>>>
annotations: Annotations.Schema<Types.Simplify<TypeLiteral.Type<{}, [{ key: K; value: V }]>>>
): record<K, V>
}

Expand All @@ -2071,7 +2060,7 @@ class $record<K extends Schema.All, V extends Schema.All> extends $typeLiteral<
constructor(readonly key: K, readonly value: V, ast?: AST.AST) {
super({}, [{ key, value }], ast)
}
annotations(annotations: Annotations.Schema<Simplify<TypeLiteral.Type<{}, [{ key: K; value: V }]>>>) {
annotations(annotations: Annotations.Schema<Types.Simplify<TypeLiteral.Type<{}, [{ key: K; value: V }]>>>) {
return new $record(this.key, this.value, _schema.annotations(this.ast, annotations))
}
}
Expand Down

0 comments on commit 1c20353

Please sign in to comment.