Skip to content

Commit 62ac034

Browse files
author
Jacob Logan
committed
add function type display
1 parent 6385358 commit 62ac034

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/components/ApiDocs/display/ParameterType.tsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ interface typeDataType {
1919
target: number;
2020
name: string;
2121
};
22+
signatures?: number[];
2223
}
2324
interface ParameterComponentType {
2425
typeData: typeDataType;
@@ -33,6 +34,9 @@ export const ParameterType = ({ typeData }: ParameterComponentType) => {
3334
if (typeData.kind === 256) {
3435
typeType = 'declaration';
3536
}
37+
if (typeData.kind === 2048) {
38+
typeType = 'function';
39+
}
3640

3741
// adds type arguments to an array to be rendered
3842
const addTypeArgs = (
@@ -84,6 +88,12 @@ export const ParameterType = ({ typeData }: ParameterComponentType) => {
8488
return typeData.name;
8589
case 'array':
8690
return <ArrayType data={typeData.elementType} />;
91+
case 'function':
92+
let functionSig;
93+
if (typeData?.signatures) {
94+
functionSig = references[typeData.signatures[0]];
95+
}
96+
return <FunctionType data={functionSig} />;
8797
default:
8898
if (typeof typeType === 'object' && typeType !== null) {
8999
return <ParameterType typeData={typeType} />;
@@ -93,8 +103,6 @@ export const ParameterType = ({ typeData }: ParameterComponentType) => {
93103
};
94104

95105
const ArrayType = ({ data }) => {
96-
console.log('ARRAY TYPE');
97-
console.log(data);
98106
return (
99107
<>
100108
<ParameterType typeData={data} />
@@ -103,6 +111,27 @@ const ArrayType = ({ data }) => {
103111
);
104112
};
105113

114+
const FunctionType = ({ data }) => {
115+
if (!data) return 'Function';
116+
const functionTypeArray: (string | React.JSX.Element)[] = ['('];
117+
if (data.parameters) {
118+
data.parameters.forEach((paramId, idx) => {
119+
if (idx !== 0) {
120+
functionTypeArray.push(', ');
121+
}
122+
const param = references[paramId];
123+
functionTypeArray.push(
124+
<ParameterType typeData={param} key={param.name} />
125+
);
126+
});
127+
}
128+
functionTypeArray.push(') => ');
129+
functionTypeArray.push(
130+
<ParameterType typeData={data.type} key={data.type.name} />
131+
);
132+
return functionTypeArray;
133+
};
134+
106135
const ReferenceType = ({ data }) => {
107136
// should be a link that loads the next type when clicked on
108137
const referencedObject = references[data.target];

0 commit comments

Comments
 (0)