https://github.com/m0ksem/unplugin-print-type
Transform TS type to string
https://github.com/m0ksem/unplugin-print-type
render-type ts types types-to-string typescript unplugin vite webpack
Last synced: 3 months ago
JSON representation
Transform TS type to string
- Host: GitHub
- URL: https://github.com/m0ksem/unplugin-print-type
- Owner: m0ksem
- License: mit
- Created: 2022-07-28T21:09:29.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-17T01:42:23.000Z (about 2 years ago)
- Last Synced: 2025-06-28T00:04:52.003Z (4 months ago)
- Topics: render-type, ts, types, types-to-string, typescript, unplugin, vite, webpack
- Language: TypeScript
- Homepage:
- Size: 170 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# unplugin-print-type
Experimental TS type printer.
Print TS type deeply handle all subtypes. Useful if you want to document types.
## Features
- Render type during build (Zero runtime-code)
- Render type aliases and interfaces to string
- Resolve imported types
## Usage
```ts
import type { UserRole } from './user'
interface User {
name: string
role: UserRole
}
console.log(`User type: ${PrintType()}`)
```
Output
```plain
User type: {
name: string
role: 'admin' | 'user'
}
```
## Install
```bash
npm i unplugin-print-type
```
Vite
```ts
// vite.config.ts
import Untype from 'unplugin-print-type/vite'
export default defineConfig({
plugins: [
Untype({ /* options */ }),
],
})
```
Example: [`playground/`](./playground/)
Webpack
```ts
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-print-type/webpack')({ /* options */ })
]
}
```
Nuxt
```ts
// nuxt.config.js
export default {
buildModules: [
['unplugin-print-type/nuxt', { /* options */ }],
],
}
```
> This module works for both Nuxt 2 and [Nuxt Vite](https://github.com/nuxt/vite)
Vue CLI
```ts
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-print-type/webpack')({ /* options */ }),
],
},
}
```