How to extract selected types from d.ts to create new types file, i.e new d.ts file

Viewed 138

I've typescript code similar to the below

import * as z from 'zod';


const schema = z.strictObject({
  jobName: z.string().nonempty(),
  startAfter: z.date(),
  retry: z.boolean().optional(),
  retryAfter: dateSchema.optional(),
  runCount: z.number().optional(),
  data: z.record(z.any()).optional(),
  status: z.enum(['ready', 'running', 'finished']).optional()
})

export type Job = z.infer<typeof schema>;

Job type is inferred from Zod schema

I would like to use only Job type in other projects, so I need to copy only Job type to another types file. Is this possible with tsc or are there any other options?

I can't add project with Job type as dependency so, can't use type import

I've tried compiling all source files to out one single d.ts file, but due to some extra transformations we apply on some types, vscode intellisense is slow with that fat d.ts file.

0 Answers
Related