Skip to content

Commit 2b1fbe9

Browse files
committed
Strip away unsupported types in constructor arguments
Related to #56 Related to #65 Closes #66
1 parent ba8f743 commit 2b1fbe9

4 files changed

Lines changed: 57 additions & 0 deletions

File tree

lib/parse/ParameterLoader.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,14 @@ export class ParameterLoader {
244244
return { type: 'raw', value: 'string' };
245245
case AST_NODE_TYPES.TSTypeLiteral:
246246
return { type: 'hash', value: typeNode };
247+
case AST_NODE_TYPES.TSUnknownKeyword:
248+
case AST_NODE_TYPES.TSUndefinedKeyword:
249+
case AST_NODE_TYPES.TSVoidKeyword:
250+
case AST_NODE_TYPES.TSNullKeyword:
251+
case AST_NODE_TYPES.TSAnyKeyword:
252+
case AST_NODE_TYPES.TSUnionType:
253+
case AST_NODE_TYPES.TSTupleType:
254+
return { type: 'undefined' };
247255
}
248256
throw new Error(`Could not understand parameter type ${typeNode.type} of ${errorIdentifier
249257
} in ${this.classLoaded.localName} at ${this.classLoaded.fileName}`);
@@ -424,6 +432,8 @@ export type ParameterRangeUnresolved = {
424432
} | {
425433
type: 'hash';
426434
value: TSTypeLiteral;
435+
} | {
436+
type: 'undefined';
427437
};
428438

429439
export type ParameterRangeResolved = {

lib/parse/ParameterResolver.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ export class ParameterResolver {
9393
type: 'nested',
9494
value: await this.getNestedFieldsFromHash(range.value, owningClass),
9595
};
96+
case 'undefined':
97+
return {
98+
type: 'undefined',
99+
};
96100
}
97101
}
98102

test/parse/ParameterLoader.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,41 @@ export interface A{
10641064
},
10651065
});
10661066
});
1067+
1068+
it('should get the range of an unknown type as undefined', async() => {
1069+
expect(await getFieldRange('fieldA: unknown', {}))
1070+
.toEqual({ type: 'undefined' });
1071+
});
1072+
1073+
it('should get the range of an undefined type as undefined', async() => {
1074+
expect(await getFieldRange('fieldA: undefined', {}))
1075+
.toEqual({ type: 'undefined' });
1076+
});
1077+
1078+
it('should get the range of an any type as undefined', async() => {
1079+
expect(await getFieldRange('fieldA: any', {}))
1080+
.toEqual({ type: 'undefined' });
1081+
});
1082+
1083+
it('should get the range of an void type as undefined', async() => {
1084+
expect(await getFieldRange('fieldA: void', {}))
1085+
.toEqual({ type: 'undefined' });
1086+
});
1087+
1088+
it('should get the range of a null type as undefined', async() => {
1089+
expect(await getFieldRange('fieldA: null', {}))
1090+
.toEqual({ type: 'undefined' });
1091+
});
1092+
1093+
it('should get the range of a union type as undefined', async() => {
1094+
expect(await getFieldRange('fieldA: number | string', {}))
1095+
.toEqual({ type: 'undefined' });
1096+
});
1097+
1098+
it('should get the range of a tuple type as undefined', async() => {
1099+
expect(await getFieldRange('fieldA: [ number, string ]', {}))
1100+
.toEqual({ type: 'undefined' });
1101+
});
10671102
});
10681103

10691104
describe('getFieldDefault', () => {

test/parse/ParameterResolver.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,14 @@ export interface MyInterface extends IgnoredInterface{};
359359
value: [],
360360
});
361361
});
362+
363+
it('should handle an undefined range', async() => {
364+
expect(await loader.resolveRange({
365+
type: 'undefined',
366+
}, classReference)).toMatchObject({
367+
type: 'undefined',
368+
});
369+
});
362370
});
363371

364372
describe('resolveRangeInterface', () => {

0 commit comments

Comments
 (0)