Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
babel-plugin-ts-definitions-to-proptypes
Advanced tools
Generate React PropTypes from TypeScript definitions.
A Babel plugin to generate React PropTypes from TypeScript definitinos.
// Example.d.ts
// Before
import React from 'react';
export interface Props {
name?: string;
}
// After
import React from 'react';
import PropTypes from 'prop-types';
export const Props = {
name: PropTypes.string
};
// Example.js
import React from 'react';
import Props from './Example.d.ts';
export class Example extends React.Component {
static propTypes = Props;
render() {
return <div />;
}
}
npm i -D babel-plugin-ts-definitions-to-proptypes
Add the plugin to your Babel config. It's preferred to enable this plugin for development only, or when building a library.
// babel.config.js
const plugins = [];
if (process.env.NODE_ENV !== 'production') {
plugins.push('babel-plugin-ts-definitions-to-proptypes');
}
module.exports = {
// Required
presets: ['@babel/preset-typescript', '@babel/preset-react']
plugins,
};
When transpiling down to ES5 or lower, the @babel/plugin-proposal-class-properties
plugin is
required.
customPropTypeSuffixes
(string[]) - Reference custom types directly when they match one of the
provided suffixes. This option requires the type to be within the file itself, as imported types
would be automatically removed by Babel. Defaults to []
.module.exports = {
plugins: [['babel-plugin-ts-definitions-to-proptypes', { customPropTypeSuffixes: ['Shape'] }]],
};
// Before
import React from 'react';
import PropTypes from 'prop-types';
const NameShape = PropTypes.string;
interface Props {
name?: NameShape;
}
class Example extends React.Component<Props> {
render() {
return <div />;
}
}
// After
import React from 'react';
import PropTypes from 'prop-types';
const NameShape = PropTypes.string;
class Example extends React.Component {
static propTypes = {
name: NameShape,
};
render() {
return <div />;
}
}
FAQs
Generate React PropTypes from TypeScript definitions.
The npm package babel-plugin-ts-definitions-to-proptypes receives a total of 1 weekly downloads. As such, babel-plugin-ts-definitions-to-proptypes popularity was classified as not popular.
We found that babel-plugin-ts-definitions-to-proptypes demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.