Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix react-native ref type #916

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ exports[`plugin typescript with "native", "ref" and "expandProps" option adds im
import Svg from "react-native-svg";
import type { SvgProps } from "react-native-svg";
import { Ref, forwardRef } from "react";
const SvgComponent = (props: SvgProps, ref: Ref<SVGSVGElement>) => <Svg><g /></Svg>;
const SvgComponent = (props: SvgProps, ref: Ref<Svg>) => <Svg><g /></Svg>;
const ForwardRef = forwardRef(SvgComponent);
export default ForwardRef;"
`;
Expand All @@ -404,7 +404,7 @@ exports[`plugin typescript with "native", "ref" option adds import from "react-n
"import * as React from "react";
import Svg from "react-native-svg";
import { Ref, forwardRef } from "react";
const SvgComponent = (_, ref: Ref<SVGSVGElement>) => <Svg><g /></Svg>;
const SvgComponent = (_, ref: Ref<Svg>) => <Svg><g /></Svg>;
const ForwardRef = forwardRef(SvgComponent);
export default ForwardRef;"
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ const tsTypeReferenceSVGRef = (ctx: Context) => {
getOrCreateImport(ctx, ctx.importSource).specifiers.push(
t.importSpecifier(identifier, identifier),
)
if (ctx.opts.native) {
return t.tsTypeReference(
identifier,
t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier('Svg'))]),
)
}
return t.tsTypeReference(
identifier,
t.tsTypeParameterInstantiation([
Expand Down