Giter Site home page Giter Site logo

rbxts-transformer-t's Introduction

rbxts-transformer-t

TypeScript transformer which converts TypeScript types to t entities

Installation

To install this package run the following command:

npm i rbxts-transformer-t

Usage

To use this transformer you have to add rbxts-transformer-t to your tsconfig.json file in compilerOptions config

"plugins": [
	{
		"transform": "rbxts-transformer-t",
	}
]

Before

import { $terrify } from "rbxts-transformer-t";

interface Data {
	Color: Color3;
	Name: string;
	Material: Enum.Material;
}

const tType = $terrify<Data>();

After

local t = TS.import(script, TS.getModule(script, "t").lib.ts).t

local tType = t.interface({
	Color = t.Color3,
	Name = t.string,
	Material = t.enum(Enum.Material),
})

About this transformer

What it can do

  1. Transform almost all TypeScript types into t models:
  • null, undefined, void, unknown
  • string, boolean and number literals
  • string, boolean, number, any and thread types
  • arrays, tuples, maps, objects and functions
  • type unions and intersections
  • interfaces types
  • roblox types such as Enum Axes
  • Enums to enum ex. Enum.Material => t.enum(Enum.Material)
  1. Compute expressions passed into it.

For example, this expression

$terrify<Omit<{ foo: 'bar', bar: number } & { data: string }, 'bar'>>()

will be converted into

local t = TS.import(script, TS.getModule(script, "t").lib.ts).t

t.interface({
	foo = t.literal("bar"),
	data = t.string,
})

What it can't do

  1. Transform classes.

  2. Work with dynamic type parameters, i.e. $terrify<T>() in the following code will error:

import { $terrify } from 'rbxts-transformer-t'

function convertEntity<T>(entity: T) {
  return $terrify<T>()
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.