Skip to content

Commit 342c2c1

Browse files
committed
feat: string and number types
1 parent f91f804 commit 342c2c1

13 files changed

Lines changed: 34 additions & 39 deletions

File tree

src/props.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import type {
88
BooleanType,
99
LiteralType,
1010
NullType,
11+
NumberType,
1112
ObjectType,
1213
PropDescriptor,
14+
StringType,
1315
TypeDescriptor,
1416
UndefinedType,
1517
UnionType,
@@ -117,6 +119,18 @@ function parseType(type: Type<ts.Type>): TypeDescriptor {
117119
} as NullType;
118120
}
119121

122+
if (type.isString()) {
123+
return {
124+
name: "string",
125+
} as StringType;
126+
}
127+
128+
if (type.isNumber()) {
129+
return {
130+
name: "number",
131+
} as NumberType;
132+
}
133+
120134
if (type.isObject() || type.isInterface() || type.isAnonymous()) {
121135
return {
122136
name: "object",

src/types.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ export interface BooleanType extends BaseType {
6161
name: "boolean";
6262
}
6363

64+
export interface NumberType extends BaseType {
65+
name: "number";
66+
}
67+
68+
export interface StringType extends BaseType {
69+
name: "string";
70+
}
71+
6472
export interface ObjectType extends BaseType {
6573
name: "object";
6674
properties: Record<string, TypeDescriptor & { required?: boolean }>;
@@ -73,7 +81,9 @@ export type TypeDescriptor =
7381
| NullType
7482
| UndefinedType
7583
| BooleanType
76-
| ObjectType;
84+
| ObjectType
85+
| StringType
86+
| NumberType;
7787

7888
export interface PropDescriptor {
7989
type: TypeDescriptor;

tests/individual/boolean-literal-prop copy/input.tsx

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

tests/individual/boolean-literal-prop copy/output.json

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

tests/individual/inline-props-type/output.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"props": {
55
"myProp": {
66
"type": {
7-
"name": "unknown",
8-
"raw": "string"
7+
"name": "string"
98
},
109
"required": true
1110
}

tests/individual/interface-props-type-default-alias/output.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"props": {
55
"myProp": {
66
"type": {
7-
"name": "unknown",
8-
"raw": "string"
7+
"name": "string"
98
},
109
"required": true,
1110
"description": "My prop",

tests/individual/interface-props-type-default/output.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"props": {
55
"myProp": {
66
"type": {
7-
"name": "unknown",
8-
"raw": "string"
7+
"name": "string"
98
},
109
"required": true,
1110
"description": "My prop",

tests/individual/interface-props-type-description-tag-alias/output.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"props": {
55
"myProp": {
66
"type": {
7-
"name": "unknown",
8-
"raw": "string"
7+
"name": "string"
98
},
109
"required": true,
1110
"description": "My prop description"

tests/individual/interface-props-type-description-tag/input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ interface Props {
44
*
55
* @description My prop description
66
*/
7-
myProp: string;
7+
myProp: number;
88
}
99

1010
export function MyComp(props: Props) {

tests/individual/interface-props-type-description-tag/output.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"props": {
55
"myProp": {
66
"type": {
7-
"name": "unknown",
8-
"raw": "string"
7+
"name": "number"
98
},
109
"required": true,
1110
"description": "My prop description"

0 commit comments

Comments
 (0)