mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 03:23:29 +01:00
refactor: update makeURLSearchParams to accept readonly non-Records (#8868)
This commit is contained in:
@@ -58,4 +58,31 @@ describe('makeURLSearchParams', () => {
|
||||
expect([...params.entries()]).toEqual([['foo', 'bar']]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('types', () => {
|
||||
interface TestInput {
|
||||
foo: string;
|
||||
}
|
||||
|
||||
test("GIVEN object without index signature THEN TypeScript doesn't raise a type error", () => {
|
||||
// Previously, `makeURLSearchParams` used `Record<string, unknown>` as an input, but that meant that it
|
||||
// couldn't accept most interfaces, since they don't have an index signature. This test is to make sure
|
||||
// non-Records can be used without casting.
|
||||
|
||||
const input = { foo: 'bar' } as TestInput;
|
||||
const params = makeURLSearchParams(input);
|
||||
|
||||
expect([...params.entries()]).toEqual([['foo', 'bar']]);
|
||||
});
|
||||
|
||||
test("GIVEN readonly object on a non-readonly generic type THEN TypeScript doesn't raise a type error", () => {
|
||||
// While `Readonly<T>` type was always accepted in `makeURLSearchParams`, this test is to ensure that we can
|
||||
// use the generic type and accept `Readonly<T>` rather than only [possibly] mutable `T`.
|
||||
|
||||
const input = Object.freeze({ foo: 'bar' } as TestInput);
|
||||
const params = makeURLSearchParams<TestInput>(input);
|
||||
|
||||
expect([...params.entries()]).toEqual([['foo', 'bar']]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user