An open API service indexing awesome lists of open source software.

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

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 */ }),
],
},
}
```