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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export IWithData and IWithForm types #65

Merged
merged 1 commit into from
Mar 2, 2021

Conversation

jdforsythe
Copy link
Contributor

Fixes #63

Exports IWithData and IWithForm types
Explicitly makes generic extend IOptionsBase
Changes IWithData's data property to be string, Buffer, or object (allows strings, Buffers, objects, or arrays)

No behavior is affected so no new tests were written

Example usage - you can now construct a typed options object using the IWithData or IWithForm types.

import * as phin from 'phin';

export const app = async () => {
  const stringOpts: phin.IWithData<phin.IOptions> = {
    url: 'http://localhost:8008',
    parse: 'none',
    data: '1',
  };

  const bufferOpts: phin.IWithData<phin.IOptions> = {
    url: 'http://localhost:8008',
    parse: 'none',
    data: Buffer.from('1'),
  };

  const objectOpts: phin.IWithData<phin.IOptions> = {
    url: 'http://localhost:8008',
    parse: 'none',
    data: { val: 1 },
  };

  const arrayOpts: phin.IWithData<phin.IOptions> = {
    url: 'http://localhost:8008',
    parse: 'none',
    data: [{ val: 1 }],
  };

  const res1 = await phin(stringOpts);
  const res2 = await phin(bufferOpts);
  const res3 = await phin(objectOpts);
  const res4 = await phin(arrayOpts);

  console.log(res1.body);
  console.log(res2.body);
  console.log(res3.body);
  console.log(res4.body);
};

If you think something should be added to documentation, let me know.

Fixes ethan7g#63

Exports IWithData and IWithForm types
Explicitly makes generic extend IOptionsBase
Changes IWithData's data property to be string, Buffer, or object (allows strings, Buffers, objects, or arrays)

No behavior is affected so no new tests were written
@ethan7g ethan7g merged commit 80c6b3f into ethan7g:master Mar 2, 2021
@ethan7g
Copy link
Owner

ethan7g commented Mar 2, 2021

Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type for options for POST request not exported
2 participants