Effect-TS / schema

Modeling the schema of data structures as first-class values

Home Page:https://effect.website

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't extract type from a union of literals

davidsainez opened this issue · comments

What version of @effect/schema is running?

No response

What steps can reproduce the bug?

I create a union of literals like so:

const Literals = S.literal("foo", "bar");  

But when trying to extract the type using interface:

interface Literals extends S.Schema.To<typeof Literals> {} 

I get the following error:

typescript [2312]: An interface can only extend an object type or intersection of object types with statically known members. 

But if I use a type alias (and avoid extends) it works fine.

type Literals = S.Schema.To<typeof Literals>

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

I'm just getting started with this library so apologies in advance if this is intentional

In TypeScript you can't extend union types

type Literals = "foo" | "bar" // ok

interface Literals2 extends Literals {}
/*
An interface can only extend an object type or intersection of object types with statically known members.ts(2312)
*/

https://www.totaltypescript.com/concepts/an-interface-can-only-extend-an-object-type