Skip to content

Conversation

@DemonHa
Copy link

@DemonHa DemonHa commented Sep 2, 2025

Currently Module.Import types are not working correctly when we wrap the Record type with an optional field.

See example:

const UserSchema = Type.Object({
  id: Type.String({ format: "uuid" }),
  email: Type.String({ format: "email" }),
  account: Type.Optional(Type.Ref("Account")),
});

const AccountSchema = Type.Object({
  id: Type.String({ format: "uuid" }),
  name: Type.String(),
  users: Type.Array(Type.Ref("User")),
  events: Type.Optional(
    Type.Record(
      Type.String(), // event name (e.g. "user.created")
      Type.Object({
        message: Type.Union([
          Type.Literal("welcome"),
          Type.Literal("reminder"),
        ]),
      })
    )
  ),
});

const Module = Type.Module({
  User: UserSchema,
  Account: AccountSchema,
});

const Account = Module.Import("Account");

// Wrong type:
// events?: {} | undefined;
type AccountType = Static<typeof Account>;

This PR fixes the types to return the correct type for this specific case

@DemonHa DemonHa merged commit d92aeea into master Sep 2, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants