All Projects â†’ Thinkmill â†’ magical-types

Thinkmill / magical-types

Licence: other
🔮 Document React components and other stuff typed with TypeScript magically

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

🔮 magical-types

Document React components and other stuff typed with TypeScript magically

Getting Started

Installing babel-plugin-macros

magical-types is used as a Babel Macro. Unless you're using Create React App or Gatsby, you'll need to install it and add it to your Babel config.

yarn add babel-plugin-macros
{
  "plugins": ["babel-plugin-macros"]
}

Installing magical-types

yarn add @magical-types/macro

Using it

import { PropTypes, FunctionTypes, RawTypes } from "@magical-types/macro";

type Props = {
  someProp: string;
};

let MyComponent = (props: Props) => {
  return <div />;
};

<PropTypes component={MyComponent} />;

function myFunctionThatDoesCoolStuff(someArgument: { thing: true }) {}

<FunctionTypes function={myFunctionThatDoesCoolStuff} />;

type SomeObject = { someProperty: boolean };

<RawTypes<SomeObject> />;

function someFunctionThatReturnsAComponent() {
  return MyComponent;
}

let AnotherComp = someFunctionThatReturnsAComponent();

<PropTypes component={AnotherComp} />;

Thanks/Inspiration

This project is mostly some ideas that I've been thinking about because of some of the constraints in react-docgen, react-docgen-typescript and extract-react-types and how some problems could be removed by changing some constraints, notably the removal of having to know what is and isn't a React component.

The code for rendering types is heavily based off pretty-proptypes.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].