Giter VIP home page Giter VIP logo

Comments (2)

ThomasAribart avatar ThomasAribart commented on July 21, 2024 2

@valyagolev Hope I'm not answering too late.

I already had this issue in other libs. This is some TS internals dark magic that I don't understand anything about, but it will work if you use a second unconstrained generic like this:

export type GPTFunction = {
  name: string;
  description?: string;
  parameters: { type: "object" } & JSONSchema;
};

export type Return<T extends GPTFunction> = FromSchema<T["parameters"]>;

export const SetImprovedDescription = {
  name: "set_improved_description",
  description: "Set improved description",
  parameters: {
    type: "object",
    properties: {
      description: { type: "string" },
      explanation_for_changes: { type: "string" },
    },
    required: ["description"],
    additionalProperties: false,
  },
} as const satisfies GPTFunction;

// Will work !
function call_gpt<T extends GPTFunction, R = Return<T>>(
  schema: T,
  system: string,
  user: string,
): null | R {
  return null;
}

const a = call_gpt(SetImprovedDescription, "system", "user");

Will add a section in the FAQ about that!

from json-schema-to-ts.

ThomasAribart avatar ThomasAribart commented on July 21, 2024

FAQ added: https://github.com/ThomasAribart/json-schema-to-ts/blob/main/documentation/FAQs/applying-from-schema-on-generics.md

Cheers !

from json-schema-to-ts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.