Home How to declare flow types for REST API
Reply: 0

How to declare flow types for REST API

user2193
1#
user2193 Published in May 21, 2018, 4:51 pm

=====EDIT=====

Thanks to @kalley I updated my declaration file and made a bit of progress. I don't have a linting error anymore, but I still can't get the type to be recognizes where I import them. I updated the content of the files above

=====end EDIT=====

I'm trying to create flow type for a REST API that I consume for a project I"m working on.

I'm running into an issues: the types are not being seen when i'm editing the source using the new type

Here is the file which contains the types (src/flow-typed/API.js)

// @flow

declare module "API" {
  //  type Error = {code:number, message:string};
  declare export type ImageJSON = {
    url: string,
    reference: string
  };

  declare export type CategoryJSON = {
    reference: number,
    name: string,
    slug: string,
    icon: ImageJSON,
    children: [],
    created_at: string
  };

  declare export type CompanyJSON = {
    reference: number,
    name: string,
    slug: string,
    email: string,
    occupational_medicine: string,
    psychology_of_work: string,
    logo: ImageJSON,
    categories: Array<CategoryJSON>,
    created_at: string
  };

  declare export type GetCompanyResponse = {
    error: Error,
    company: CompanyJSON
  };

  // declare export default GetCompanyResponse
}

I import the file this way

import typeof { GetCompanyResponse } from "../flow-typed/API";

I get the following flow error:

[flow] Named import from module `../flow-typed/WazzaAPI` (This module only has a default export. Did you mean `import GetCompanyResponse from ...`?)

If I import the file like so import typeof GetCompanyResponse from "../flow-typed/API";

Then in the code I get an error saying the GetCompanyResponse does not have an error member:

.then((response: GetCompanyResponse) => {
    //check to see if there is an error
    if (response.error.code !== ERROR_CODE.noError) {

The error:

[flow] property `error` (Property not found in exports)

Any pointers appreciated

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.390419 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO