Skip to content

Commit

Permalink
fix: calling with symbol throwing error on startsWith check (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
james-elicx authored Aug 16, 2023
1 parent cee0cf1 commit 84b0638
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/chatty-cups-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'cf-bindings-proxy': patch
---

Symbol call throwing error due to prop check assuming string.
3 changes: 2 additions & 1 deletion src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ export const createBindingProxy = <T>(bindingId: string, notChainable = false):
return new Proxy({ __bindingId: bindingId, __calls: [], __chainUntil: [] } as BindingRequest, {
get(target, prop: string) {
// internal properties
if (prop.startsWith('__')) return target[prop as keyof BindingRequest];
if (typeof prop === 'string' && prop.startsWith('__'))
return target[prop as keyof BindingRequest];
// ignore toJSON calls
if (prop === 'toJSON') return undefined;
if (notChainable) return undefined;
Expand Down
8 changes: 8 additions & 0 deletions tests/proxy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,12 @@ suite('bindings', () => {
expect(list.objects.length).toEqual(0);
});
});

suite('other patches', () => {
test('Calling `binding()` with a Symbol should not throw error for `startsWith` check', () => {
const kv = binding<KVNamespace>('KV');
// @ts-expect-error - testing it doesn't throw an error, not that it works
expect(kv[Symbol.toStringTag]).toBeDefined();
});
});
});

0 comments on commit 84b0638

Please sign in to comment.