- fix(scoped-jsx): Don't add
JSX
import ifJSX
is already imported (#458f5152b6
by @henryqdineen)
-
Avoid modifying import not from
'react'
when replacing types. (#4565614a5f
by @henryqdineen) -
Fix a bug when replacing types in shorthand array type notations. (#455
70a1ea5
by @henryqdineen)For example, replacing
ReactText
inReactText[]
should now result in(number | string)[]
instead ofnumber | string[]
.
-
Run
no-implicit-ref-callback-return
andreact-element-default-any
by default inpreset-19
(#43310085c8
by @eps1lon)The transformed code is not meant to be used as a pattern for new code. It really is about migrating existing code with as little friction. Changes can always be reverted and a subset chosen.
-
Declare dependency on
@babel/types
(#435a7cc3ce
by @huozhi)Fixes
types-react-codemod tried to access @babel/types, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound
-
Add
--yes
option to skip prompts (#432f0b075f
by @eps1lon)Useful when applying presets when no user input is available or desired.
-
Add
react-element-default-any-props
codemod (#3714191845
by @eps1lon)Opt-in codemod in
preset-19
.// implies `React.ReactElement<unknown>` in React 19 as opposed to `React.ReactElement<any>` in prior versions. -declare const element: React.ReactElement +declare const element: React.ReactElement<any>
Only meant to migrate old code not a recommendation for how to type React elements.
-
Add
no-implicit-ref-callback-return
transform (#3697535bfc
by @eps1lon)Ensures you don't accidentally return anything from ref callbacks since the return value was always ignored. With ref cleanups, this is no longer the case and flagged in types to avoid mistakes.
-<div ref={current => (instance = current)} /> +<div ref={current => {instance = current}} />
The transform is opt-in in the
preset-19
in case you already used ref cleanups in Canary releases.
-
Add codemod to replace deprecated
ReactFragment
by inlining its actual type (#326ed97a70
by @eps1lon)import * as React from 'react'; -const node: React.ReactFragment +const node: Iterable<React.ReactNode>
-
Add codemod to replace deprecated React types related to propTypes with their counterpart from the
prop-types
package (#3571751318
by @eps1lon)+import * as PropTypes from "prop-types"; import * as React from "react"; -declare const requireable: React.Requireable<React.ReactNode>; +declare const requireable: PropTypes.Requireable<React.ReactNode>; -declare const validator: React.Validator<React.ReactNode>; +declare const requireable: PropTypes.Validator<React.ReactNode>; -declare const validationMap: React.ValidationMap<{}>; +declare const requireable: PropTypes.ValidationMap<React.ReactNode>; -declare const weakValidationMap: React.WeakValidationMap<{}>; +declare const requireable: PropTypes.WeakValidationMap<React.ReactNode>;
-
Add codemod for required initial value in
useRef
(#2170047404
by @eps1lon)Added as
useRef-required-initial
. Can be used on 18.x types but only intended for once DefinitelyTyped/DefinitelyTyped#64920 lands. -
Unflag codemods for new refs (#319
80fe29c
by @eps1lon)Just removing their experimental prefix since we have increased confidence in these changes after seeing their impact internally.
-experimental-refobject-defaults +refobject-defaults
-
Add codemod to replace
LegacyRef
withRef
(#347e928761
by @eps1lon) -
Add codemod to replace deprecated
ReactNodeArray
by inlining its actual type. (#325b7f757c
by @eps1lon)import * as React from 'react'; -const node: React.ReactNodeArray +const node: ReadonlyArray<React.ReactNode>
-
Added missing transforms as choices to preset-19 (#341
dc10a3d
by @eps1lon) -
Ensure added imports of types use the
type
modifier (#343f05624f
by @eps1lon)If we'd previously add an import to
JSX
(e.g. inscoped-jsx
), the codemod would import it as a value. This breaks TypeScript projects usingverbatimModuleSyntax
as well as projects enforcingtype
imports for types.Now we ensure new imports of types use the
type
modifier:-import { JSX } from 'react' +import { type JSX } from 'react'
This also changes how we transform the deprecated global JSX namespace. Instead of rewriting each usage, we opt for adding another import. The guiding principle being that we keep the changes minimal in a codemod.
Before:
import * as React from 'react' -const element: JSX.Element +const element: React.JSX.Element
After:
import * as React from 'react' +import { type JSX } from 'react' const element: JSX.Element
Note that rewriting of imports does not change the modifier. For example, the
deprecated-vfc-codemod
rewritesVFC
identifiers toFC
. If the import ofVFC
had notype
modifier, the codemod will not add one.type
modifiers for import specifiers require [TypeScript 4.5 which has reached EOL](https://github.com/DefinitelyTyped/DefinitelyTyped#support-window in DefinitelyTyped) which is a strong signal that you should upgrade to at least TypeScript 4.6 by now. -
Ensure replace and rename codemods have consistent behavior (#348
a62832e
by @eps1lon)Fixes multiple incorrect transform patterns that were supported by some transforms but not others. We no longer switch to
type
imports if the original type wasn't imported with that modifier. Type parameters are now consistently preserved. We don't add a reference to theReact
namespace anymore if we can just add a type import.This affects the following codemods:
deprecated-legacy-ref
deprecated-react-child
deprecated-react-text
deprecated-react-type
deprecated-sfc-element
deprecated-sfc
deprecated-stateless-component
deprecated-void-function-component
-
Find and replace type usage in type parameters of call expressions (#344
8c27551
by @eps1lon)Now we properly detect that e.g.
JSX
is used insomeFunctionWithTypeParameters<JSX>()
.Affected codemods:
deprecated-react-child
deprecated-react-text
scoped-jsx
-
#304
0730d90553bd7dfc889a1325c9e975c16f367439
Thanks @renovate! - Update Node.js support matrixDrop support for unmaintained Node.js versions (14.x, 16.x, 17.x, and 19.x) to reduce maintenance cost.
-
#214
10fb254afbccab5e7e1941bfee49f957ca7ed1a5
Thanks @eps1lon! - Add scoped-jsx transformThis replaces usage of the deprecated global JSX namespace with usage of the scoped namespace:
+import { JSX } from 'react' const element: JSX.Element
-
#208
b76beab
Thanks @eps1lon! - Add experimental (not for use in published types)experimental-refobject-defaults
codemod for newRefObject
behavior
- #248
0dd5d20
Thanks @dgarciamuria! - Add missing@babel/parser
dependency
-
#210
a47bd09
Thanks @eps1lon! - Ensure jscodeshift can be executedFixes
/usr/bin/env: ‘node\r’: No such file or directory
-
#143
b3351d2
Thanks @eps1lon! - Fail install if used version of Node.js is not officially supportedAdd a list of supported versions of Node.js to
engines
inpackage.json
. If the current version does not match, installation will fail (by default in Yarn and in NPM only if theengine-strict
config is enabled).This warning can be ignored either by setting
engine-strict
tofalse
in NPM (default) or add--ignore-engines
toyarn
(e.g.yarn --ignore-engines
).
-
#92
0d92140
Thanks @eps1lon! - Ensure TypeScript instantiation expressions can be parsedInstantiation expressions were added in TypeScript 4.7.
-
#69
52da899
Thanks @eps1lon! - Don't useimport
statement.Fixes errors like "SyntaxError: Cannot use import statement outside a module".
-
#63
15ec796
Thanks @eps1lon! - Avoid transpiling transformsPreviously jscodeshift would transpile the transforms before using them. This was largely unnecessary and resulted in bugs to to usage of undeclared Babel dependencies.
-
#46
c0784a7
Thanks @eps1lon! - Parse .ts files without JSX plugin.Otherwise code such as
(<RegExp>expected).test(object);
could not be parsed.
-
#33
59e5624
Thanks @eps1lon! - Remove repository config files from release.These files are only relevant for development.
-
#40
e425cc9
Thanks @eps1lon! - Remove test files from release.There's a charm to having these in the release but nobody reads them anyway. And for testing you need the dev setup which is probably not available if inside node_modules.