Releases: eps1lon/types-react-codemod
v3.5.3
v3.5.2
Patch Changes
- fix(scoped-jsx): Don't add
JSXimport ifJSXis already imported (#458f5152b6by @henryqdineen)
v3.5.1
Patch Changes
-
Avoid modifying import not from
'react'when replacing types. (#4565614a5fby @henryqdineen) -
Fix a bug when replacing types in shorthand array type notations. (#455
70a1ea5by @henryqdineen)For example, replacing
ReactTextinReactText[]should now result in(number | string)[]instead ofnumber | string[].
v3.5.0
Minor Changes
-
Run
no-implicit-ref-callback-returnandreact-element-default-anyby default inpreset-19(#43310085c8by @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.
v3.4.1
v3.4.0
v3.3.0
Minor Changes
-
Add
react-element-default-any-propscodemod (#3714191845by @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.
v3.2.0
Minor Changes
-
Add
no-implicit-ref-callback-returntransform (#3697535bfcby @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-19in case you already used ref cleanups in Canary releases.
v3.1.1
v3.1.0
Minor Changes
-
Add codemod to replace deprecated
ReactFragmentby inlining its actual type (#326ed97a70by @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-typespackage (#3571751318by @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(#2170047404by @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
80fe29cby @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
LegacyRefwithRef(#347e928761by @eps1lon) -
Add codemod to replace deprecated
ReactNodeArrayby inlining its actual type. (#325b7f757cby @eps1lon)import * as React from 'react'; -const node: React.ReactNodeArray +const node: ReadonlyArray<React.ReactNode>
Patch Changes
-
Added missing transforms as choices to preset-19 (#341
dc10a3dby @eps1lon) -
Ensure added imports of types use the
typemodifier (#343f05624fby @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 usingverbatimModuleSyntaxas well as projects enforcingtypeimports for types.Now we ensure new imports of types use the
typemodifier:-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.ElementNote that rewriting of imports does not change the modifier.
For example, thedeprecated-vfc-codemodrewritesVFCidentifiers toFC.
If the import ofVFChad notypemodifier, the codemod will not add one.typemodifiers 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
a62832eby @eps1lon)Fixes multiple incorrect transform patterns that were supported by some transforms but not others.
We no longer switch totypeimports if the original type wasn't imported with that modifier.
Type parameters are now consistently preserved.
We don't add a reference to theReactnamespace anymore if we can just add a type import.This affects the following codemods:
deprecated-legacy-refdeprecated-react-childdeprecated-react-textdeprecated-react-typedeprecated-sfc-elementdeprecated-sfcdeprecated-stateless-componentdeprecated-void-function-component
-
Find and replace type usage in type parameters of call expressions (#344
8c27551by @eps1lon)Now we properly detect that e.g.
JSXis used insomeFunctionWithTypeParameters<JSX>().Affected codemods:
deprecated-react-childdeprecated-react-textscoped-jsx