Skip to content

Commit b788564

Browse files
Support multiple ReturnValueTypes for func props (#867)
1 parent d06be3a commit b788564

File tree

6 files changed

+79
-12
lines changed

6 files changed

+79
-12
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"cpy-cli": "^3.1.1",
1616
"del-cli": "^3.0.1",
1717
"devextreme": "23.1-next",
18-
"devextreme-internal-tools": "10.0.0-beta.17",
18+
"devextreme-internal-tools": "10.0.0-beta.19",
1919
"eslint": "^7.32.0",
2020
"eslint-config-airbnb-base": "^14.2.1",
2121
"eslint-config-airbnb-typescript": "^12.3.1",

packages/devextreme-react-generator/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"author": "Developer Express Inc.",
33
"name": "devextreme-react-generator",
4-
"version": "4.1.3",
4+
"version": "4.1.7",
55
"description": "DevExtreme React UI and Visualization Components",
66
"repository": {
77
"type": "git",

packages/devextreme-react-generator/src/generator.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,4 +1258,70 @@ describe('mapWidget', () => {
12581258
expect(getComplexOptionType(types, typeResolver)).toEqual(expected);
12591259
});
12601260
});
1261+
1262+
describe('getComplexOptionType for func with multiple return types', () => {
1263+
const types = [
1264+
{
1265+
type: 'Function',
1266+
acceptableValues: [],
1267+
isCustomType: false,
1268+
importPath: '',
1269+
isImportedType: false,
1270+
params: [],
1271+
returnValueTypes: [{
1272+
type: 'String',
1273+
}, {
1274+
type: 'Number',
1275+
},
1276+
],
1277+
},
1278+
];
1279+
1280+
const expected = '(() => string | number)';
1281+
1282+
it('should return multiple types', () => {
1283+
expect(getComplexOptionType(types)).toEqual(expected);
1284+
});
1285+
});
1286+
1287+
describe('getComplexOptionType for func with single return type', () => {
1288+
const types = [
1289+
{
1290+
type: 'Function',
1291+
acceptableValues: [],
1292+
isCustomType: false,
1293+
importPath: '',
1294+
isImportedType: false,
1295+
params: [],
1296+
returnValueTypes: [{
1297+
type: 'String',
1298+
}],
1299+
},
1300+
];
1301+
1302+
const expected = '(() => string)';
1303+
1304+
it('should return single type', () => {
1305+
expect(getComplexOptionType(types)).toEqual(expected);
1306+
});
1307+
});
1308+
1309+
describe('getComplexOptionType for func with empty returnValueTypes IMD', () => {
1310+
const types = [
1311+
{
1312+
type: 'Function',
1313+
acceptableValues: [],
1314+
isCustomType: false,
1315+
importPath: '',
1316+
isImportedType: false,
1317+
params: [],
1318+
},
1319+
];
1320+
1321+
const expected = '(() => any)';
1322+
1323+
it('should return any fallback type', () => {
1324+
expect(getComplexOptionType(types)).toEqual(expected);
1325+
});
1326+
});
12611327
});

packages/devextreme-react-generator/src/generator.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ enum BaseTypes {
5454
Null = 'null',
5555
True = 'true',
5656
False = 'false',
57+
void = 'void',
5758
}
5859

5960
const UNKNOWN_MODULE = 'UNKNOWN_MODULE';
@@ -139,9 +140,9 @@ export function getComplexOptionType(
139140
return `${p.name}: ${parameterType === BaseTypes.Object ? BaseTypes.Any : parameterType}`;
140141
})
141142
.join(', ') || '';
142-
const returnType = (
143-
functionDescriptor.returnValueType && (formatTypeDescriptor(functionDescriptor.returnValueType) || (functionDescriptor.returnValueType.type === 'void' && 'void'))
144-
) || BaseTypes.Any;
143+
const returnType = functionDescriptor.returnValueTypes
144+
? functionDescriptor.returnValueTypes.map((t) => formatTypeDescriptor(t)).join(' | ')
145+
: BaseTypes.Any;
145146
return `(${parameters}) => ${returnType}`;
146147
}
147148

packages/devextreme-react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"@types/react": "^16.14.28",
3737
"@types/react-dom": "^16.9.16",
3838
"del": "^3.0.0",
39-
"devextreme-react-generator": "^4.1.3",
39+
"devextreme-react-generator": "^4.1.7",
4040
"gulp": "^4.0.2",
4141
"gulp-header": "^2.0.9",
4242
"gulp-shell": "^0.8.0",

0 commit comments

Comments
 (0)