Skip to content

Infer for modules/scopes #1591

@xixixao

Description

@xixixao

Request a feature

🤷 Motivation

If I have a big scope/module I don't want to have to pull out all the types one by one an refer to them

💡 Solution

This works:

type InferModule<M> = {
  [K in keyof M]: M[K] extends { infer: infer O } ? O : never;
};

used like:

const MlflowSchema = type.module({
  SearchExperimentsResponse: {
    experiments: "Experiment[]",
    next_page_token: "string?",
  },
  Experiment: {
    experiment_id: "string"
  },
});

type MlflowSchema = InferScope<typeof MlflowSchema>;

If this is already "built-in" I could not find it in the docs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    To do

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions