Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

FetchOptions has no property uri #189

Closed
corydeppen opened this issue Oct 30, 2017 · 9 comments
Closed

FetchOptions has no property uri #189

corydeppen opened this issue Oct 30, 2017 · 9 comments

Comments

@corydeppen
Copy link

Intended outcome:
No compilation errors.

Actual outcome:
Get a TS error TS2459: Type 'FetchOptions | undefined' has no property 'uri' and no string index signature when compiling a simple CRA app.

How to reproduce the issue:
Using [email protected], I have the following code to create an ApolloClient:

const client = new ApolloClient({
  cache: new InMemoryCache(),
  // causes an error when compiled
  link: createHttpLink({ uri: 'http://localhost:4000/graphql' })
  // works fine
  // link: new HttpLink({ uri: 'http://localhost:4000/graphql' })
});

It's very strange and I don't see anything obviously wrong with the declaration file (/path/to/node_modules/apollo-link-http/lib/httpLink.d.ts) that would cause this. What makes it more odd is that it seems to only happen the first time it's compiled, but if I make a change that forces a recompilation it will typically build without a problem. I'm wondering if anyone else has seen this before or could think of what might be causing it.

@Grmiade
Copy link

Grmiade commented Nov 1, 2017

The problem is this line export declare const createHttpLink: ({uri, fetch: fetcher, includeExtensions, ...requestOptions}?: FetchOptions) => ApolloLink;. We can't extract a uri field if the param can be undefined (?) :/

@Grmiade
Copy link

Grmiade commented Nov 15, 2017

Any news?

@corydeppen
Copy link
Author

I'm no longer seeing this issue using [email protected]. Can someone else confirm?

@Grmiade
Copy link

Grmiade commented Nov 22, 2017

I still have this problem :/
If you try to rm -rf node_modules and npm install. It's always fixed?

@corydeppen
Copy link
Author

Yeah, I started from a clean node_modules directory. The only things I had to manually tweak were the fix for the lodash.flowright issue in react-apollo and setting "strictNullChecks": false in tsconfig.json to get around the return type issue in apollo-client. Running yarn outdated confirms all packages are current.

@Grmiade
Copy link

Grmiade commented Nov 22, 2017

strictNullChecks: falseallow to fix this issue too I think. Because our issue is we can’t extract an explicit field from an undefined parameter.

@corydeppen
Copy link
Author

By moving the destructuring out of the parameter into the body of createHttpLink, the declaration output from tsc looks more appropriate and it runs without error.

// httpLink.ts
export const createHttpLink = (options?: FetchOptions) => {
  let { uri, fetch: fetcher, includeExtensions, ...requestOptions } = options;
  // ...
};

// httpLink.d.ts
export declare const createHttpLink: (options?: FetchOptions) => ApolloLink;

@jbaxleyiii
Copy link
Contributor

hmmm, I'm happy to merge and release that PR but that should certainly be valid typescript and not show that error. If the changes work though I'm happy with it!

jbaxleyiii pushed a commit that referenced this issue Dec 8, 2017
* Fix typescript destructuring error, #189

* Update changelog
@evans
Copy link
Contributor

evans commented Feb 15, 2018

Thank you for the fix!

@evans evans closed this as completed Feb 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants