0.1.2 • Published 7 months ago

unplugin-print-type v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

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

import type { UserRole } from './user'

interface User {
  name: string
  role: UserRole
}

console.log(`User type: ${PrintType<User>()}`)

Output

User type: {
  name: string
  role: 'admin' | 'user'
}

Install

npm i unplugin-print-type
// vite.config.ts
import Untype from 'unplugin-print-type/vite'

export default defineConfig({
  plugins: [
    Untype({ /* options */ }),
  ],
})

Example: playground/

// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    require('unplugin-print-type/webpack')({ /* options */ })
  ]
}

// nuxt.config.js
export default {
  buildModules: [
    ['unplugin-print-type/nuxt', { /* options */ }],
  ],
}

This module works for both Nuxt 2 and Nuxt Vite

// vue.config.js
module.exports = {
  configureWebpack: {
    plugins: [
      require('unplugin-print-type/webpack')({ /* options */ }),
    ],
  },
}

0.1.0

7 months ago

0.1.2

7 months ago

0.1.1

7 months ago

0.0.3

2 years ago

0.0.2

2 years ago