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 mikearnaldi committed Apr 16, 2024
1 parent e7e1bbe commit 9aeae46
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
@@ -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
Expand Up @@ -48,17 +48,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 @@ -2023,16 +2012,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 @@ -2043,8 +2032,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 @@ -2136,7 +2125,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 @@ -2147,7 +2136,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 @@ -2174,7 +2163,7 @@ export interface $Record<K extends Schema.All, V extends Schema.All> extends Typ
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 @@ -2185,7 +2174,7 @@ class $RecordImpl<K extends Schema.All, V extends Schema.All> extends TypeLitera
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 9aeae46

Please sign in to comment.