Skip to content

Commit b466f46

Browse files
release: 3.1.0 (#318)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 1d7ef5d commit b466f46

12 files changed

+127
-151
lines changed

.changeset/chilled-actors-mate.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

.changeset/chilled-oranges-sit.md

Lines changed: 0 additions & 44 deletions
This file was deleted.

.changeset/chilly-lamps-greet.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

.changeset/eight-jeans-appear.md

Lines changed: 0 additions & 18 deletions
This file was deleted.

.changeset/famous-nails-destroy.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

.changeset/fifty-cheetahs-dance.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

.changeset/kind-bugs-teach.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

.changeset/ninety-elephants-jam.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

.changeset/short-zoos-type.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

.changeset/three-bananas-lick.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,131 @@
11
# types-react-codemod
22

3+
## 3.1.0
4+
5+
### Minor Changes
6+
7+
- Add codemod to replace deprecated `ReactFragment` by inlining its actual type ([#326](https://github.com/eps1lon/types-react-codemod/pull/326) [`ed97a70`](https://github.com/eps1lon/types-react-codemod/commit/ed97a701c9802b5b53e0a3b9da04f519793eddf3) by [@eps1lon](https://github.com/eps1lon))
8+
9+
```diff
10+
import * as React from 'react';
11+
12+
-const node: React.ReactFragment
13+
+const node: Iterable<React.ReactNode>
14+
```
15+
16+
- Add codemod to replace deprecated React types related to propTypes with their counterpart from the `prop-types` package ([#357](https://github.com/eps1lon/types-react-codemod/pull/357) [`1751318`](https://github.com/eps1lon/types-react-codemod/commit/1751318d6189fd2d44875292b6b6c23af5678d6a) by [@eps1lon](https://github.com/eps1lon))
17+
18+
```diff
19+
+import * as PropTypes from "prop-types";
20+
import * as React from "react";
21+
-declare const requireable: React.Requireable<React.ReactNode>;
22+
+declare const requireable: PropTypes.Requireable<React.ReactNode>;
23+
-declare const validator: React.Validator<React.ReactNode>;
24+
+declare const requireable: PropTypes.Validator<React.ReactNode>;
25+
-declare const validationMap: React.ValidationMap<{}>;
26+
+declare const requireable: PropTypes.ValidationMap<React.ReactNode>;
27+
-declare const weakValidationMap: React.WeakValidationMap<{}>;
28+
+declare const requireable: PropTypes.WeakValidationMap<React.ReactNode>;
29+
```
30+
31+
- Add codemod for required initial value in `useRef` ([#217](https://github.com/eps1lon/types-react-codemod/pull/217) [`0047404`](https://github.com/eps1lon/types-react-codemod/commit/0047404d18665a2b18c0859e013d643022fc23e5) by [@eps1lon](https://github.com/eps1lon))
32+
33+
Added as `useRef-required-initial`.
34+
Can be used on 18.x types but only intended for once https://github.com/DefinitelyTyped/DefinitelyTyped/pull/64920 lands.
35+
36+
- Unflag codemods for new refs ([#319](https://github.com/eps1lon/types-react-codemod/pull/319) [`80fe29c`](https://github.com/eps1lon/types-react-codemod/commit/80fe29c4bde096d5f18ec5d7bac55ad27c5c9718) by [@eps1lon](https://github.com/eps1lon))
37+
38+
Just removing their experimental prefix since we have increased confidence in these changes after seeing their impact internally.
39+
40+
```diff
41+
-experimental-refobject-defaults
42+
+refobject-defaults
43+
```
44+
45+
- Add codemod to replace `LegacyRef` with `Ref` ([#347](https://github.com/eps1lon/types-react-codemod/pull/347) [`e928761`](https://github.com/eps1lon/types-react-codemod/commit/e9287614259225cab789ed4cbf570c2940050cab) by [@eps1lon](https://github.com/eps1lon))
46+
47+
- Add codemod to replace deprecated `ReactNodeArray` by inlining its actual type. ([#325](https://github.com/eps1lon/types-react-codemod/pull/325) [`b7f757c`](https://github.com/eps1lon/types-react-codemod/commit/b7f757c08c1bbfa5ceecf47c937cfd588b37d1db) by [@eps1lon](https://github.com/eps1lon))
48+
49+
```diff
50+
import * as React from 'react';
51+
52+
-const node: React.ReactNodeArray
53+
+const node: ReadonlyArray<React.ReactNode>
54+
```
55+
56+
### Patch Changes
57+
58+
- Added missing transforms as choices to preset-19 ([#341](https://github.com/eps1lon/types-react-codemod/pull/341) [`dc10a3d`](https://github.com/eps1lon/types-react-codemod/commit/dc10a3de2fccc7fcc31e73bd655fac0f45977392) by [@eps1lon](https://github.com/eps1lon))
59+
60+
- Ensure added imports of types use the `type` modifier ([#343](https://github.com/eps1lon/types-react-codemod/pull/343) [`f05624f`](https://github.com/eps1lon/types-react-codemod/commit/f05624f41f66504293066d36b07a9b1f22b62ea2) by [@eps1lon](https://github.com/eps1lon))
61+
62+
If we'd previously add an import to `JSX` (e.g. in `scoped-jsx`),
63+
the codemod would import it as a value.
64+
This breaks TypeScript projects using `verbatimModuleSyntax` as well as projects enforcing `type` imports for types.
65+
66+
Now we ensure new imports of types use the `type` modifier:
67+
68+
```diff
69+
-import { JSX } from 'react'
70+
+import { type JSX } from 'react'
71+
```
72+
73+
This also changes how we transform the deprecated global JSX namespace.
74+
Instead of rewriting each usage, we opt for adding another import.
75+
The guiding principle being that we keep the changes minimal in a codemod.
76+
77+
Before:
78+
79+
```diff
80+
import * as React from 'react'
81+
82+
-const element: JSX.Element
83+
+const element: React.JSX.Element
84+
```
85+
86+
After:
87+
88+
```diff
89+
import * as React from 'react'
90+
+import { type JSX } from 'react'
91+
92+
const element: JSX.Element
93+
```
94+
95+
Note that rewriting of imports does not change the modifier.
96+
For example, the `deprecated-vfc-codemod` rewrites `VFC` identifiers to `FC`.
97+
If the import of `VFC` had no `type` modifier, the codemod will not add one.
98+
99+
`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.
100+
101+
- Ensure replace and rename codemods have consistent behavior ([#348](https://github.com/eps1lon/types-react-codemod/pull/348) [`a62832e`](https://github.com/eps1lon/types-react-codemod/commit/a62832e496b4c0a77119d3115cf1c157c1c04e29) by [@eps1lon](https://github.com/eps1lon))
102+
103+
Fixes multiple incorrect transform patterns that were supported by some transforms but not others.
104+
We no longer switch to `type` imports if the original type wasn't imported with that modifier.
105+
Type parameters are now consistently preserved.
106+
We don't add a reference to the `React` namespace anymore if we can just add a type import.
107+
108+
This affects the following codemods:
109+
110+
- `deprecated-legacy-ref`
111+
- `deprecated-react-child`
112+
- `deprecated-react-text`
113+
- `deprecated-react-type`
114+
- `deprecated-sfc-element`
115+
- `deprecated-sfc`
116+
- `deprecated-stateless-component`
117+
- `deprecated-void-function-component`
118+
119+
- Find and replace type usage in type parameters of call expressions ([#344](https://github.com/eps1lon/types-react-codemod/pull/344) [`8c27551`](https://github.com/eps1lon/types-react-codemod/commit/8c275511d46cd2320c9075e9e15b82f9f3aa1309) by [@eps1lon](https://github.com/eps1lon))
120+
121+
Now we properly detect that e.g. `JSX` is used in `someFunctionWithTypeParameters<JSX>()`.
122+
123+
Affected codemods:
124+
125+
- `deprecated-react-child`
126+
- `deprecated-react-text`
127+
- `scoped-jsx`
128+
3129
## 3.0.0
4130

5131
### Major Changes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "types-react-codemod",
3-
"version": "3.0.0",
3+
"version": "3.1.0",
44
"bin": "bin/types-react-codemod.cjs",
55
"scripts": {
66
"format": "prettier . --write",

0 commit comments

Comments
 (0)