Skip to content

Commit

Permalink
Fix setNativeProps type (#2058)
Browse files Browse the repository at this point in the history
Setting Object to the props type does not allow passing any object to the method. So in TypeScript when using the method for example with Path, you will get an error when passing the d. Instead ob Object, you should use at least P so it allows the original props of the component you are using.
  • Loading branch information
fauri13 committed May 23, 2023
1 parent dfec171 commit 9883614
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/elements/G.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type {
CommonPathProps,
FontProps,
NumberProp,
TransformProps,
} from '../lib/extract/types';
import Shape from './Shape';
import RNSVGGroup from '../fabric/GroupNativeComponent';
Expand All @@ -22,9 +21,10 @@ export default class G<P> extends Shape<GProps & P> {
static displayName = 'G';

setNativeProps = (
props: Object & {
matrix?: number[];
} & TransformProps,
props: GProps &
P & {
matrix?: number[];
},
) => {
const matrix = !props.matrix && extractTransform(props);
if (matrix) {
Expand Down
3 changes: 1 addition & 2 deletions src/elements/Polygon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export default class Polygon extends Shape<PolygonProps> {
};

setNativeProps = (
props: Object & {
points?: string | NumberProp[];
props: PolygonProps & {
d?: string;
},
) => {
Expand Down
3 changes: 1 addition & 2 deletions src/elements/Polyline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export default class Polyline extends Shape<PolylineProps> {
};

setNativeProps = (
props: Object & {
points?: string | NumberProp[];
props: PolylineProps & {
d?: string;
},
) => {
Expand Down
2 changes: 1 addition & 1 deletion src/elements/Shape.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export default class Shape<P> extends Component<P> {
return this.root;
}
setNativeProps = (
props: Object & {
props: P & {
matrix?: ColumnMajorTransformMatrix;
fill?: ColorValue;
} & TransformProps,
Expand Down
4 changes: 1 addition & 3 deletions src/elements/Svg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ export default class Svg extends Shape<SvgProps> {
};

setNativeProps = (
props: Object & {
width?: NumberProp;
height?: NumberProp;
props: SvgProps & {
bbWidth?: NumberProp;
bbHeight?: NumberProp;
},
Expand Down
5 changes: 2 additions & 3 deletions src/elements/TSpan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type {
FontProps,
NumberArray,
NumberProp,
TransformProps,
} from '../lib/extract/types';
import RNSVGTSpan from '../fabric/TSpanNativeComponent';

Expand All @@ -30,10 +29,10 @@ export default class TSpan extends Shape<TSpanProps> {
static displayName = 'TSpan';

setNativeProps = (
props: Object & {
props: TSpanProps & {
matrix?: ColumnMajorTransformMatrix;
style?: [] | {};
} & TransformProps,
},
) => {
const matrix = !props.matrix && extractTransform(props);
if (matrix) {
Expand Down
5 changes: 2 additions & 3 deletions src/elements/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {
NumberArray,
NumberProp,
TextSpecificProps,
TransformProps,
} from '../lib/extract/types';
import { pickNotNil } from '../lib/util';
import Shape from './Shape';
Expand All @@ -30,10 +29,10 @@ export default class Text extends Shape<TextProps> {
static displayName = 'Text';

setNativeProps = (
props: Object & {
props: TextProps & {
matrix?: ColumnMajorTransformMatrix;
style?: [] | {};
} & TransformProps,
},
) => {
const matrix = props && !props.matrix && extractTransform(props);
if (matrix) {
Expand Down

0 comments on commit 9883614

Please sign in to comment.