Skip to content

Commit 4589e9f

Browse files
🐛 Fixes variable name clash bug (#169)
* 🐛 Fixes variable name clash bug * docs(changeset): Fixes a bug where variable names clash with type properties of the same name, causing a "Missing converter for: [path]" error
1 parent d889453 commit 4589e9f

File tree

4 files changed

+77
-1
lines changed

4 files changed

+77
-1
lines changed

.changeset/shiny-dolls-kiss.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'extract-react-types': patch
3+
---
4+
5+
Fixes a bug where variable names clash with type properties of the same name, causing a "Missing converter for: [path]" error

packages/extract-react-types/__snapshots__/converters-typescript.test.js.snap

+53
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,59 @@ Object {
233233
}
234234
`;
235235

236+
exports[`TypeScript: does not conflict with ambiguously named type properties 1`] = `
237+
Object {
238+
"kind": "generic",
239+
"name": Object {
240+
"kind": "id",
241+
"name": "Icon",
242+
"type": null,
243+
},
244+
"value": Object {
245+
"kind": "object",
246+
"members": Array [
247+
Object {
248+
"key": Object {
249+
"kind": "id",
250+
"name": "size",
251+
},
252+
"kind": "property",
253+
"leadingComments": Array [
254+
Object {
255+
"raw": " Icon sizes",
256+
"type": "commentLine",
257+
"value": "Icon sizes",
258+
},
259+
],
260+
"optional": true,
261+
"value": Object {
262+
"kind": "union",
263+
"types": Array [
264+
Object {
265+
"kind": "string",
266+
"value": "small",
267+
},
268+
Object {
269+
"kind": "string",
270+
"value": "medium",
271+
},
272+
Object {
273+
"kind": "string",
274+
"value": "large",
275+
},
276+
Object {
277+
"kind": "string",
278+
"value": "xlarge",
279+
},
280+
],
281+
},
282+
},
283+
],
284+
"referenceIdName": "IconProps",
285+
},
286+
}
287+
`;
288+
236289
exports[`TypeScript: follow export default export 1`] = `
237290
Object {
238291
"kind": "generic",

packages/extract-react-types/converters-typescript.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,24 @@ const TESTS = [
618618
619619
export default MyComponent;
620620
`
621+
},
622+
{
623+
name: 'does not conflict with ambiguously named type properties ',
624+
typeSystem: 'typescript',
625+
code: `
626+
import React, { FC } from 'react';
627+
628+
const size = 'My var name conflicts with the property name';
629+
630+
export interface IconProps {
631+
// Icon sizes
632+
size?: 'small' | 'medium' | 'large' | 'xlarge';
633+
}
634+
635+
const Icon: FC<IconProps> = ({ size = 'medium' }) => null;
636+
637+
export default Icon;
638+
`
621639
}
622640
];
623641

packages/extract-react-types/src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ converters.TSTypeLiteral = (path, context): K.Obj => ({
846846
converters.TSPropertySignature = (path, context): K.Property => ({
847847
kind: 'property',
848848
optional: !!path.node.optional,
849-
key: convert(path.get('key'), context),
849+
key: { kind: 'id', name: path.node.key.name },
850850
value: convert(path.get('typeAnnotation'), context)
851851
});
852852

0 commit comments

Comments
 (0)