# ts-transformer-vue-props

> A TypeScript custom transformer which generate vue3 props for given type.

Latest version **0.0.1** (published 2022-11-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install ts-transformer-vue-props
pnpm add ts-transformer-vue-props
yarn add ts-transformer-vue-props
bun add ts-transformer-vue-props
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2022-11-15 |
| First published | 2022-11-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | lloydzhou |
| Maintainers | lloydzhou |
| Keywords | TypeScript |

## Links

- npm: https://www.npmjs.com/package/ts-transformer-vue-props
- Repository: https://github.com/lloydzhou/ts-transformer-vue-props
- Homepage: https://github.com/lloydzhou/ts-transformer-vue-props#readme
- Issues: https://github.com/lloydzhou/ts-transformer-vue-props/issues
- npm.io page: https://npm.io/package/ts-transformer-vue-props

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2022-11-15

## README

# ts-transformer-vue-props
A TypeScript custom transformer which generate vue3 props for given type.

[![NPM version][npm-image]][npm-url]
[![Downloads](https://img.shields.io/npm/dm/ts-transformer-vue-props.svg)](https://www.npmjs.com/package/ts-transformer-vue-props)

# How to use this package

This package exports 2 functions.
One is `props` which is used in TypeScript codes to obtain props of given type, while the other is a TypeScript custom transformer which is used to compile the `props` function correctly.

## How to use `props`

```ts
import { props } from 'ts-transformer-vue-props';

interface Props {
  id: string;
  name: string;
  age: number;
}
const p = props<Props>();

console.log(p);
--->
{
    "id": String,
    "name": String,
    "age": Number
}
```

## How to use the custom transformer

Unfortunately, TypeScript itself does not currently provide any easy way to use custom transformers (See https://github.com/Microsoft/TypeScript/issues/14419).
The followings are the example usage of the custom transformer.

### webpack (with ts-loader or awesome-typescript-loader)

```js
// webpack.config.js
const propsTransformer = require('ts-transformer-vue-props/transformer').default;

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.ts$/,
        loader: 'ts-loader', // or 'awesome-typescript-loader'
        options: {
          // make sure not to set `transpileOnly: true` here, otherwise it will not work
          getCustomTransformers: program => ({
              before: [
                  propsTransformer(program)
              ]
          })
        }
      }
    ]
  }
};

```

### Rollup (with rollup-plugin-typescript2)

```js
// rollup.config.js
import resolve from 'rollup-plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';
import propsTransformer from 'ts-transformer-vue-props/transformer';

export default {
  // ...
  plugins: [
    resolve(),
    typescript({ transformers: [service => ({
      before: [ propsTransformer(service.getProgram()) ],
      after: []
    })] })
  ]
};
```

### ttypescript

See [ttypescript's README](https://github.com/cevek/ttypescript/blob/master/README.md) for how to use this with module bundlers such as webpack or Rollup.

```jsonc
// tsconfig.json
{
  "compilerOptions": {
    // ...
    "plugins": [
      { "transform": "ts-transformer-vue-props/transformer" }
    ]
  },
  // ...
}
```

# License

MIT

[npm-image]:https://img.shields.io/npm/v/ts-transformer-vue-props.svg?style=flat
[npm-url]:https://npmjs.org/package/ts-transformer-vue-props

---
_Source: https://npm.io/package/ts-transformer-vue-props · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
