Skip to content

Commit

Permalink
fix: forceMultiPart TypeScript Definition for Options (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
KidSysco authored Nov 6, 2023
1 parent a35ddf8 commit 18f0b04
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ When an options object is provided, the result types will be accurately inferred
```ts
import formAutoContent from 'form-auto-content';

const option = { payload: 'body', headers: 'head' } as const
const option = {
payload: 'body',
headers: 'head',
forceMultiPart: true,
} as const;

const myCustomForm = formAutoContent({
field1: 'value1',
Expand Down
3 changes: 2 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Readable } from "stream";

export type FormMethodOptions = {
readonly payload?: string,
readonly headers?: string
readonly headers?: string,
readonly forceMultiPart?: boolean
}

type FormMethodDefaultOptions = {
Expand Down
25 changes: 25 additions & 0 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,28 @@ import { Readable } from "stream";
// @ts-expect-error
}, { foo: '' } as const);
}

{ // Test for forceMultiPart option set to true
const option = { forceMultiPart: true } as const;

const myForm = formAutoContent(
{
field1: 'value1',
field2: ['value2', 'value2.2'],
},
option
);

expectAssignable<{ payload: Readable; headers: Record<string, string> }>(myForm);
}

{ // Test for forceMultiPart option set to false
const option = { forceMultiPart: false } as const;

const myForm = formAutoContent({
field1: 'value1',
field2: ['value2', 'value2.2']
}, option);

expectAssignable<{ payload: Readable, headers: Record<string, string> }>(myForm);
}

0 comments on commit 18f0b04

Please sign in to comment.