Skip to content

Commit

Permalink
fix(no-forward-ref): loose fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hyoban committed Jan 23, 2025
1 parent 41ee491 commit fab6b8e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ ruleTester.run(RULE_NAME, rule, {
interface ComponentProps {
foo: string;
}
const Component = function Component({ ref, ...props }: ComponentProps & { ref: React.RefObject<HTMLElement> }) {
const Component = function Component({ ref, ...props }: ComponentProps & { ref?: React.RefObject<HTMLElement | null> }) {
return <div ref={ref} />;
};
`,
Expand All @@ -211,7 +211,7 @@ ruleTester.run(RULE_NAME, rule, {
errors: [{ messageId: "noForwardRef" }],
output: /* tsx */ `
import * as React from 'react'
const Component = function Component({ ref, ...props }: { foo: string } & { ref: React.RefObject<HTMLElement> }) {
const Component = function Component({ ref, ...props }: { foo: string } & { ref?: React.RefObject<HTMLElement | null> }) {
return <div ref={ref}>{props.foo}</div>;
};
`,
Expand All @@ -231,7 +231,7 @@ ruleTester.run(RULE_NAME, rule, {
errors: [{ messageId: "noForwardRef" }],
output: /* tsx */ `
import * as React from 'react'
const Component = function Component({ ref, foo }: { foo: string } & { ref: React.RefObject<HTMLElement> }) {
const Component = function Component({ ref, foo }: { foo: string } & { ref?: React.RefObject<HTMLElement | null> }) {
return <div ref={ref}>{foo}</div>;
};
`,
Expand All @@ -251,7 +251,7 @@ ruleTester.run(RULE_NAME, rule, {
errors: [{ messageId: "noForwardRef" }],
output: /* tsx */ `
import * as React from 'react'
const Component = function Component({ ref: r, foo }: { foo: string } & { ref: React.RefObject<HTMLElement> }) {
const Component = function Component({ ref: r, foo }: { foo: string } & { ref?: React.RefObject<HTMLElement | null> }) {
return <div ref={r}>{foo}</div>;
};
`,
Expand All @@ -271,7 +271,7 @@ ruleTester.run(RULE_NAME, rule, {
errors: [{ messageId: "noForwardRef" }],
output: /* tsx */ `
import * as React from 'react'
const Component = function Component({ ref: r, foo, ...rest }: { foo: string, bar: number } & { ref: React.RefObject<HTMLElement> }) {
const Component = function Component({ ref: r, foo, ...rest }: { foo: string, bar: number } & { ref?: React.RefObject<HTMLElement | null> }) {
return <div ref={r}>{foo}</div>;
};
`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ function getComponentPropsFixes(
getText(typeArg1),
"&",
"{",
`ref:`,
`React.RefObject<${getText(typeArg0)}>`,
`ref?:`,
`React.RefObject<${getText(typeArg0)} | null>`,
"}",
].join(" "),
),
Expand Down

0 comments on commit fab6b8e

Please sign in to comment.