Skip to content

How to get Typescript Type from ObjectRef and InputObjectRef? #735

Pinned Answered by hayes
nopain1210 asked this question in Q&A
Discussion options

You must be logged in to vote

There should probably be a docs section on this somewhere, but here are a few examples of helpers you could use:

import SchemaBuilder, {
  InputShapeFromTypeParam,
  InputTypeParam,
  InputTypeRef,
  ObjectRef,
  SchemaTypes,
  ShapeFromTypeParam,
  TypeParam,
} from '@pothos/core';

type InferInputType<T extends InputTypeRef<unknown>> = T extends InputTypeRef<infer S> ? S : never;
type InferOutputType<T extends ObjectRef<unknown>> = T extends ObjectRef<infer S> ? S : never;

const input: InferInputType<typeof ExampleInput> = { id: 1, ids: [] };
const output: InferOutputType<typeof User> = { firstName: 'a', lastName: 'b' };

// Support for lists, scalars, and other methods of referencing …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@nopain1210
Comment options

@hayes
Comment options

Answer selected by nopain1210
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants