Skip to content
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

Merged
merged 7 commits into from
Jul 25, 2023
Merged

Typescript types #24

merged 7 commits into from
Jul 25, 2023

Conversation

andersonjoseph
Copy link
Contributor

@andersonjoseph andersonjoseph commented Jul 12, 2023

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

@andersonjoseph andersonjoseph marked this pull request as draft July 12, 2023 12:54
@andersonjoseph andersonjoseph marked this pull request as ready for review July 12, 2023 13:28
Copy link
Owner

@Eomm Eomm left a 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

package.json Outdated Show resolved Hide resolved
@Eomm Eomm self-assigned this Jul 12, 2023
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>
Copy link
Owner

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?

Copy link
Contributor Author

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

Copy link
Owner

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!

@Eomm Eomm merged commit a535a07 into Eomm:main Jul 25, 2023
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typescript @types package
2 participants