serviejs/popsicle

Problem with typings: Property 'request' does not exist on type 'RequestOptions'

Closed this issue · 1 comments

I like Popsicle because of it's promise-based approach but I cannot get it to work in my TypeScript project. TypeScript is complaining about popsicle's definitions (which I installed using npm install popsicle --save ):

error TS2339: Property 'request' does not exist on type '(options: string | RequestOptions) => Request'.

Here is my code:

import popsicle from 'popsicle';
const status = require('popsicle-status');
import {ContentType} from "../ContentType";

export default class UserAPI {
  constructor(private backendURL: string) {}

  public login(email: string, password: string): any {
    const self = this;

    return popsicle.request({
      method: 'POST',
      url: `${self.backendURL}/login?persist=false`,
      body: {
        email: email,
        password: password,
      },
      headers: ContentType.JSON,
    }).use([status(), popsicle.plugins.parse('json')]);
  }
}

Screenshot

screenshot

When you do import x from, that's using the default export. You can check the definition of it, but the default export is just an alias of the request export. You can also do import { request } from 'popsicle' or, to write the code like you have it should use import *.