-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typescript types #24
Typescript types #24
Conversation
c687ac9
to
03a4a27
Compare
03a4a27
to
cb1a3ac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will check this PR soon!
Thanks
Co-authored-by: Manuel Spigolon <behemoth89@gmail.com>
types/index.d.ts
Outdated
* @param {FormMethodOptions} opts - An object containing properties to modify the output field names. | ||
* @returns {FormMethodResult} A JSON object with a payload field representing the data stream and a headers field containing the content-type set to "application/json". | ||
*/ | ||
export default function formMethod<const T extends FormMethodOptions = FormMethodDefaultOptions>(json: Record<string, unknown>, opts?: T): FormMethodResult<T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is working (note the wrong option):
const myForm = formAutoContent({
field1: 'value1',
field2: ['value2', 'value2.2']
}, { headers: 'head', foo: '' });
Could we handle it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a way to handle this case but with a con: TS won't be able to infer the correct type when using an inline object without a const assertion because the type is widened when using the helper WithoutExtraProperties
.
However, I realized this could be 'good' as the feature I'm using to infer the types in inline objects is a new feature from TS 5.0, so without this feature we can support pre TS 5.0 codebases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into it!
fc8d4da
to
2f83280
Compare
Hi馃憢
This PR adds TypeScript declaration file, some tests, and documentation.
Let me know if something is missing or needs to be changed.
Fixes: #19