Skip to content

Commit

Permalink
feat: add support for unknown type (#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanBetty authored Jan 23, 2024
1 parent c2f6df2 commit e60c422
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions __tests__/assets/unknownEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function unknownEvent({
event,
}: {
event: unknown;
}): number {
return 1;
}
17 changes: 17 additions & 0 deletions __tests__/interaction-compatibility.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ test('extract compatibility for: ({ event, price, quantity }: { event: Event, pr
});
});

test('add compatibility for unknown type', (t: Context): void => {
const compatibility = toCompatibility('__tests__/assets/unknownEvent.ts');

t.deepEqual(compatibility, {
function: `function unknownEvent(_a) {
var event = _a.event;
return 1;
}
`,
name: 'unknownEvent',
parameters: {
event: InteractionOptionType.Unknown,
},
type: InteractionOptionType.Number,
});
});

test('fail extraction when passing no interaction', (t: Context): void => {
t.throws(() => toCompatibility('__tests__/assets/empty.ts'), {
name: 'RangeError',
Expand Down
1 change: 1 addition & 0 deletions src/interactions/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const allowedTypes = [
'boolean',
'number',
'string',
'unknown',
'void',
];

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ export enum InteractionOptionType {
Void = 'Void',
Page = 'Page',
Locale = 'Locale',
Unknown = 'Unknown',
}

// TODO: Add support
Expand Down

0 comments on commit e60c422

Please sign in to comment.