https://github.com/calasanmarko/typeclone
Deeply expands TypeScript types into their own declaration file.
https://github.com/calasanmarko/typeclone
build cli clone compiler declaration javascript js transpiler ts types typescript utility
Last synced: 6 months ago
JSON representation
Deeply expands TypeScript types into their own declaration file.
- Host: GitHub
- URL: https://github.com/calasanmarko/typeclone
- Owner: calasanmarko
- License: mit
- Created: 2023-10-11T11:12:36.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-11T23:23:29.000Z (over 2 years ago)
- Last Synced: 2025-07-05T15:36:46.277Z (7 months ago)
- Topics: build, cli, clone, compiler, declaration, javascript, js, transpiler, ts, types, typescript, utility
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/typeclone
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# typeclone
Deeply expands TypeScript types into their own declaration file.
# Installation
Available as a npm package.
For usage from code:
```
npm install --save-dev typeclone
```
For usage from the command line:
```
npm install --global typeclone
```
# Usage
Available both as a command-line utility and a TypeScript module. Gets all types in the input file, expands them, and then outputs them in a separate file. Useful for getting rid of dependencies when exporting inferred types.
For example, take this input file named `demo.ts`
```
import { z } from "zod";
const demoSchema = z.object({
test: z.string(),
test2: z.number().nullable().optional(),
});
export type Demo = z.infer;
```
We can now call either the command-line utility:
```
typeclone demo.ts demo_out.d.ts
```
Or the JavaScript function:
```
import { cloneTypes } from "typeclone";
cloneTypes('demo.ts', 'demo_out.d.ts')
```
Which will result in the output file `demo_out.d.ts` with the following contents:
```
export declare type Demo = { test: string; test2?: number | null | undefined; }
```
Can output both `.ts` and `.d.ts` files, automatically detects which one based on the output file extension.
# License
Made by Marko Calasan, 2023.
This product is licensed under the MIT License.