ethanent / phin

Node HTTP client
MIT License
576 stars 33 forks source link

Type for options for POST request not exported #63

Closed jdforsythe closed 3 years ago

jdforsythe commented 3 years ago

The type used for POST requests is IWithData<phin.IOptions> but the IWithData is not exported in types.d.ts so there's no way to construct a typed options object without making a custom type.

Also, there's a note in the types about using the generics to make JSON/Form posting mutually exclusive, but wouldn't this work just as well?

export interface IOptions extends IOptionsBase {
 parse?: 'none'
}

interface WithData {
  data: object;
}

interface WithForm {
  form: {
    [index: string]: string;
  }
}

export type IOptionsWithData = IOptions & WithData;
export type IOptionsWithForm = IOptions & WithForm;
// etc
ethanent commented 3 years ago

Thanks for pointing that out. A PR would be appreciated!

jdforsythe commented 3 years ago

@ethanent PR submitted https://github.com/ethanent/phin/pull/65

I kept the generics but explicitly made the T extend IOptionsBase and updated the data property of IWithData to be compatible with what Centra accepts.