Skip to content

Instantly share code, notes, and snippets.

@Jarred-Sumner
Last active March 19, 2021 21:43
Show Gist options
  • Save Jarred-Sumner/75fb937a8bd5235bba1e4d7a984ddeac to your computer and use it in GitHub Desktop.
Save Jarred-Sumner/75fb937a8bd5235bba1e4d7a984ddeac to your computer and use it in GitHub Desktop.
Add import * as React from "react"; to the top of every TypeScript file
const addImports = require("jscodeshift-add-imports");
module.exports = function (fileInfo, api, options) {
const j = api.jscodeshift;
const code = fileInfo.source;
const root = j(code);
addImports(root, [j.template.statement`import * as React from 'react'`]);
return root.toSource();
};
jscodeshift --transform=codemod.js --extensions=.tsx,.jsx ./**/*.tsx --parser tsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment