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 Apr 9, 2024
1 parent 3fd6428 commit bf4e2c5
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 @@ -47,17 +47,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 @@ -2003,16 +1992,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 @@ -2023,8 +2012,8 @@ class typeLiteralImpl<
Fields extends Struct.Fields,
const Records extends IndexSignature.Records
> extends SchemaImpl<
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 @@ -2116,7 +2105,7 @@ class typeLiteralImpl<
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 typeLiteralImpl(this.fields, this.records, AST.annotations(this.ast, toASTAnnotations(annotations)))
}
Expand All @@ -2127,7 +2116,7 @@ class typeLiteralImpl<
* @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 @@ -2154,7 +2143,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 @@ -2165,7 +2154,7 @@ class recordImpl<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 recordImpl(this.key, this.value, AST.annotations(this.ast, toASTAnnotations(annotations)))
}
}
Expand Down

0 comments on commit bf4e2c5

Please sign in to comment.