Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema.Record doesn't support Schema.Enums as key #2811

Closed
joepjoosten opened this issue May 22, 2024 · 0 comments · Fixed by #2809
Closed

Schema.Record doesn't support Schema.Enums as key #2811

joepjoosten opened this issue May 22, 2024 · 0 comments · Fixed by #2809
Assignees
Labels
enhancement New feature or request schema

Comments

@joepjoosten
Copy link
Contributor

joepjoosten commented May 22, 2024

What version of Effect is running?

3.1.5, @effect/schema 0.67.3, Typescript 5.4.5

What steps can reproduce the bug?

import { Schema } from "@effect/schema";

enum Abc {
    A = 'a',
    B = 'b',
    C = 'c'
}

const abc = Schema.Enums(Abc);

const def = Schema.Record(abc, Schema.String);
type def = Schema.Schema.Type<typeof def>;

const test: def = {
    [Abc.A]: 'test'
}

What is the expected behavior?

In typescript it's valid to use:

enum Abc {
    A = 'a',
    B = 'b',
    C = 'c'
}

const test: Record<Abc, string> = {
    [Abc.A]: 'test'
}

What do you see instead?

Error: record: unsupported key schema (<enum 3 value(s): 0 | 1 | 2>)
    at key (/node_modules/.pnpm/@effect+schema@0.67.3_effect@3.1.5/node_modules/@effect/schema/src/AST.ts:2015:15)
    at record (/node_modules/.pnpm/@effect+schema@0.67.3_effect@3.1.5/node_modules/@effect/schema/src/AST.ts:2018:3)
    at getDefaultTypeLiteralAST (/node_modules/.pnpm/@effect+schema@0.67.3_effect@3.1.5/node_modules/@effect/schema/src/Schema.ts:2317:57)
    at makeTypeLiteralClass (/node_modules/.pnpm/@effect+schema@0.67.3_effect@3.1.5/node_modules/@effect/schema/src/Schema.ts:2348:18)
    at makeRecordClass (/node_modules/.pnpm/@effect+schema@0.67.3_effect@3.1.5/node_modules/@effect/schema/src/Schema.ts:2411:29)
    at Record (/node_modules/.pnpm/@effect+schema@0.67.3_effect@3.1.5/node_modules/@effect/schema/src/Schema.ts:2428:3)

Additional information

No response

@joepjoosten joepjoosten added the bug Something isn't working label May 22, 2024
@gcanti gcanti added enhancement New feature or request and removed bug Something isn't working labels May 22, 2024
@gcanti gcanti added the schema label May 22, 2024
@gcanti gcanti self-assigned this May 22, 2024
@gcanti gcanti closed this as completed in f8038ca May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request schema
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants